题解

213 条题解

  • 0
    @ 2017-05-20 21:13:30

    #include<stdio.h>
    #include<string.h>
    char c[1100000];
    int main()
    {
    int n,x,ans=0;

    while(~scanf("%d%d",&n,&x)){
    ans=0;
    for(int i=1;i<=n;i++)
    {
    int j=i;
    while(j>=10)
    {
    if(j%10==x){
    ans++;
    }
    j/=10;
    }
    if(j==x)ans++;
    }
    printf("%d\n",ans);
    }
    return 0;
    }

  • 0
    @ 2017-05-13 14:06:21

    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<cmath>

    using namespace std;

    int main(){
    int n, x;
    cin >> n >> x;
    int ans = 0;
    for(int i = 1; i <= n; i++){
    int num = i;
    while(num){
    if(num % 10 == x) ans++;
    num /= 10;
    }
    }
    printf("%d", ans);
    return 0;
    }

  • 0
    @ 2017-05-08 13:09:37

    一种奇葩的思路,用字符串
    (我才不在乎效率呢)

    #include <stdio.h>
    int main()
    {
        long n,times=0;
        char buf[7],x;
        scanf("%ld %c",&n,&x);
        for(long i=1;i<=n;i++)
        {
            int len=sprintf(buf,"%ld",i);
            for(int j=0;j<len;j++)
                if(buf[j]==x)
                    times++;
        }
        printf("%ld",times);
    }
    
  • 0
    @ 2017-05-06 21:08:36
    import java.util.Scanner;
    public class Main{
        public static void main(String args[]){
            Scanner in=new Scanner(System.in);
            int n,x,count=0,t;
            String now,index;
            n=in.nextInt();
            x=in.nextInt();
            index=String.valueOf(x);
            for(int i=1;i<=n;++i){
                now=String.valueOf(i);
                t=0;
                while(true){
                    t=now.indexOf(index,t);
                    if(t==-1)   break;
                    count++;
                    t++;
                }
            }
            System.out.println(count);
            in.close();
        }
    }
    
  • 0
    @ 2017-05-06 17:43:12

    #include <iostream>
    #include <cstdio>
    #include <string.h>
    #include <cmath>
    using namespace std;
    int main(){
    long long n,temp;
    int x;
    int cnt = 0;
    cin>>n>>x;
    // cout<<n<<" "<<x<<endl;
    for(long long i=1; i<=n ;i++){
    // cout<<i<<endl;
    temp = i;
    while(temp){
    if(temp%10==x)
    cnt++;
    temp /= 10;
    }
    }
    cout<<cnt<<endl;
    return 0;
    }

  • 0
    @ 2017-04-25 19:20:26

    #include<stdio.h>
    int main()
    {
    int sum=0,n,i,j,x;
    scanf("%d %d",&n,&x);
    for(i=1;i<=n;i++)
    {
    j=i;
    while(j>0)
    {
    if(j%10==x)
    sum++;
    j=j/10;
    }
    }
    printf("%d",sum);

    }

  • 0
    @ 2017-04-14 12:37:55
    #include<iostream>
    using namespace std;
    
    int main(){
        int n,x,temp,count = 0;
        cin>>n>>x;
        for(int j = 1 ; j <= n ; j++){
            int i = j;
            while(1){
                temp = i%10;
                if(x == temp)
                    count++;
                if(i/10 == 0)
                    break;
                else
                    i/=10;
            }
        }
        cout<<count;
        return 0;
    }
    
  • 0
    @ 2017-03-31 11:54:10

    #include <stdio.h>
    int main()
    {
    long n,i;
    int x;
    scanf("%d%d",&n,&x);
    int a[10];
    for(i=1;i<=9;i++) a[i]=0;
    for(i=1;i<=n;i++)
    {
    long j=i;
    while(j>0)
    {
    a[j%10]++;
    j=j/10;
    }

    }
    printf("%d",a[x]);
    }

    • @ 2017-11-06 21:01:13

      厉害了,没想到可以用数组

    • @ 2017-11-28 22:52:38

      int a[10];要在scanf("%d%d",&n,&x);之前

    • @ 2018-01-21 14:24:41

      @无言: 为什么呢,定义数组和n、x的输入有关么?

  • 0
    @ 2017-02-22 13:21:07

    #include <stdio.h>
    #include <stdlib.h>
    int main()
    {
    int n,x,a,i,sum=0;
    scanf("%d %d",&n,&x);
    for(i=1;i<=n;i++)
    {
    a=i;
    while(a>0)
    {

    if(a%10==x)
    sum++;
    a=a/10;
    }
    }
    printf("%d",sum);
    return 0;
    }

  • 0
    @ 2017-02-21 20:54:41

    从1数到n,对于每一个数分离累加

    #include <iostream>
    using namespace std;
    int num[10];
    
    void f(int n)
    {
        while(n != 0){
            num[n % 10]++;
            n /= 10;
        }
        return ; 
    }
    int main(void)
    {
        int n,t,i;
        cin>>n>>t;
    
        for(i = 1;i <= n;i++)
        {
            f(i);
        }
    
        cout<<num[t];
        return 0;
    }
    
  • 0
    @ 2017-02-14 16:43:45

    #include <stdio.h>
    int main(int argc, char const *argv[])
    {
    int n,x,j,k=0;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
    {
    j=i;
    while(j!=0)
    {
    if(x==j%10)
    {
    k+=1;
    }
    j=j/10;
    }
    }
    printf("%d\n",k );
    return 0;
    }

  • 0
    @ 2017-02-06 21:07:06
    #include<iostream>
    using namespace std;
    int main()
    {
        int n, x;
        cin >> n >> x;
        int sum = 0;
        for (int i = 1; i <= n; i++)
        {
            for (int j = i; j; j /= 10)
            {
                sum += ((j % 10) == x);
            }
        }
        cout << sum << endl;
        system("pause");
        return 0;
    }
    

    个人认为,c++的话还是数这种方法比较简单

  • 0
    @ 2017-01-13 20:23:43

    #include<cstdio>
    #define maxn 1000005
    int sh[maxn][10]={0};
    int main()
    {

    int j,m;
    for(int i=1;i<=maxn;i++)
    {
    j=i;
    while(j!=0)
    {
    m = j%10;
    sh[i][m]++;
    j=j/10;
    }
    }
    for(int i=1;i<=1000000;i++)
    for(int j=0;j<10;j++)
    sh[i][j] = sh[i-1][j]+sh[i][j];

    int n,x;
    scanf("%d%d",&n,&x);
    printf("%d\n",sh[n][x]);
    return 0 ;
    }

  • 0
    @ 2017-01-03 00:12:40

    水水水,写一遍,编译一遍,提交一遍。直接先要打印的数用二维数组存起来就好,用的时候直接打印就成。
    ```c++
    #include<cstdio>
    #define maxn 1000005
    int sh[maxn][10]={0};
    int main()
    {

    int j,m;
    for(int i=1;i<=maxn;i++)
    {
    j=i;
    while(j!=0)
    {
    m = j%10;
    sh[i][m]++;
    j=j/10;
    }
    }
    for(int i=1;i<=1000000;i++)
    for(int j=0;j<10;j++)
    sh[i][j] = sh[i-1][j]+sh[i][j];

    int n,x;
    scanf("%d%d",&n,&x);
    printf("%d\n",sh[n][x]);
    return 0 ;
    }

    • @ 2017-02-26 13:32:43

      我想问一下为什么不能while(i)
      一定要先j=i
      我用上面编出的是死循环

  • 0
    @ 2016-12-22 17:33:52

    //最简短实现
    #include<stdio.h>
    int i,k,n,p,x;
    int main()
    {
    scanf("%d%d",&n,&x);
    for(i=1;i<=n;i++)for(k=i;k;k/=10)p+=((k%10)==x);
    printf("%d",p);
    }

  • 0
    @ 2016-12-15 17:57:28

    测试数据 #0: Accepted, time = 0 ms, mem = 496 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 496 KiB, score = 10
    测试数据 #2: Accepted, time = 15 ms, mem = 496 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 496 KiB, score = 10
    测试数据 #4: Accepted, time = 15 ms, mem = 496 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 496 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 496 KiB, score = 10
    测试数据 #7: Accepted, time = 15 ms, mem = 492 KiB, score = 10
    测试数据 #8: Accepted, time = 15 ms, mem = 500 KiB, score = 10
    测试数据 #9: Accepted, time = 15 ms, mem = 496 KiB, score = 10
    Accepted, time = 75 ms, mem = 500 KiB, score = 100
    ``
    C
    #include<stdio.h>
    int main()
    {
    int n,x,i,j,a,ans=0,mod=1;
    scanf("%d%d",&n,&x);
    for(i=1;i<=n;i++)
    {
    a=i;
    while(a>0)
    {
    if(a%10==x)
    ans++;
    a=a/10;
    }
    }
    printf("%d",ans);
    return 0;
    }

    • @ 2016-12-15 17:58:23

      简单!!!!!!!!!!!!!

  • 0
    @ 2016-11-18 10:03:45

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int main(){
    int n;
    scanf("%d",&n);
    int x;
    scanf("%d",&x);
    int count=0;
    for(int i=1;i<=n;i++){
    int j=i;
    while(j!=0){
    if(j%10==x){
    count++;
    }
    j/=10;
    }
    }
    cout<<count<<endl;
    return 0;
    }

  • 0
    @ 2016-11-14 20:29:25

    宇宙第一水题
    var i,j,n,x,t:longint;
    begin
    readln(n,x);t:=0;
    for i:=1 to n do begin
    j:=i;
    while j>0 do begin
    if j mod 10=x then t:=t+1;
    j:=j div 10;
    end;
    end;
    writeln(t);
    end.

  • 0
    @ 2016-10-20 14:47:16
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int main(){
        int n,x,wei[9],num(0);
        scanf("%d%d",&n,&x);
        for(int i(1);i<=n;i++){
            int k(i),j=1;
            while(k){
                wei[j]=k%10;
                (x==wei[j++])?num++:0;
                k/=10;
            }
            memset(wei,0,sizeof(wei));***记得清零***
        }
        printf("%d\n",num);
        return 0;
    }
    
    • @ 2016-10-20 14:47:52

      记得清零

  • 0
    @ 2016-10-08 20:06:26

    #include <iostream>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <cstdlib>
    using namespace std;

    int d[10000005];

    int main() {
    int n, x, ans=0;
    cin >> n >> x;

    d[x]=1;
    for (int i=1;i <= n;i++) {
    d[i]=d[i%10];
    if (i/10) d[i]+=d[i/10];
    ans+=d[i];
    }

    cout << ans;

    return 0;
    }

    dp大法,d[i]=d[个位]+d[各位前面的数];

信息

ID
1848
难度
5
分类
(无)
标签
递交数
16580
已通过
5806
通过率
35%
被复制
36
上传者