题解

213 条题解

  • 0
    @ 2017-11-16 15:27:18

    其实我的思路非常简单,只是它给的时间限制比较小就过了

    代码如下:
    #include <stdio.h>

    int havei(int n,int i){
    if(n/10 ==0){
    if(n==i){
    return 1;
    }
    return 0;
    }
    int temp = 0,count=0;
    while(1){
    temp = n%10;
    if(temp == i){
    count++;
    }
    n= n/10;
    if(n == 0)
    break;
    }
    return count;
    }

    int main()
    {
    int n,i,ans=0;
    scanf("%d%d",&n,&i);
    while(n){
    ans +=havei(n,i);
    n--;
    }
    printf("%d",ans);
    return 0;
    }

  • 0
    @ 2017-11-06 20:52:19

    #include <stdio.h>
    #include <stdlib.h>

    /* run this program using the console pauser or add your own getch, system("pause") or input loop */
    int main()
    {int n,x,i,j,k;
    j=0;
    scanf("%d %d",&n,&x);
    for(i=1;i<=n;i++){
    k=i;
    while(k!=0){
    if(x==k%10){j++;}
    k/=10;}

    }printf("%d",j);
    return 0; }

  • 0
    @ 2017-11-06 15:23:01

    C
    循环余10判断

    #include <stdio.h>
    int main(){
        int n,x,a,ans=0;
        scanf("%d%d",&n,&x);
        for(int i=1;i<=n;i++){
            a=i;
            do{
                ans += a%10==x;
            } while(a/=10);
        }
        printf("%d\n",ans);
    }
    
  • 0
    @ 2017-11-04 07:20:34

    #include<cstdio>
    #include<iostream>
    int n,x,g,tot;
    using namespace std;
    int main()
    {
    cin>>n>>x;
    for(int i=1;i<=n;i++)
    {
    int m=i;

    while (m>0)
    {
    g=m%10; //g更新后
    m/=10;
    if(g==x) tot++;
    }

    }
    cout<<tot<<endl;
    return 0;
    }

  • 0
    @ 2017-10-31 21:22:21

    //C语言 vijos 1848

    #include <stdio.h>

    int freq_of_x(int x,int n) //函数,记录x出现的次数
    {
    int i,j,freq;
    freq=0;
    for(i=1;i<=n;++i){
    j=i; //防止i被更改。
    while(j>=1){ //写>0也行,,因为是整型,,小于1自动成0.。
    if(j%10==x) //取模
    freq++;
    j=j/10; //让每一位都成为一次个位
    }
    }
    return freq;
    }

    int main()
    {
    int x,n,freq;
    scanf("%d %d",&n,&x);
    freq=(freq_of_x(x,n));
    printf("%d",freq);
    return 0;
    }

  • 0
    @ 2017-10-31 21:19:52

    //vijos 1848

    #include <stdio.h>

    int freq_of_x(int x,int n) //函数,记录x出现的次数
    {
    int i,j,freq;
    freq=0;
    for(i=1;i<=n;++i){
    j=i; //防止i被更改。
    while(j>=1){ //写>0也行,,因为是整型,,小于1自动成0.。
    if(j%10==x) //取模
    freq++;
    j=j/10; //让每一位都成为一次个位
    }
    }
    return freq;
    }

    int main()
    {
    int x,n,freq;
    scanf("%d %d",&n,&x);
    freq=(freq_of_x(x,n));
    printf("%d",freq);
    return 0;
    }

  • 0
    @ 2017-10-30 21:40:19
    #include <stdio.h>
    
    int main()
    {
        int n, e, i, m, k, sum = 0;
        scanf("%d", &n);
        scanf("%d", &e);
        for (i = 1; i <= n; i++)
        {
            m = i;
            while (m)
            {
                k = m % 10;
                if (k == e)
                    sum++;
                m = m / 10;
            }
        }
        printf("%d\n", sum);
        return 0;
    }
    
  • 0
    @ 2017-10-30 20:21:24

    #include <iostream>
    #include <cmath>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    int main()
    {
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    int i,j,n,x,m,c=0;
    cin>>n>>x;
    for (i=1;i<=n;i++)
    {
    m=i;
    while(m!=0)
    {
    if (m%10==x)
    c++;
    m=m/10;
    }
    }
    cout<<c<<endl;
    system("pause");
    return 0;
    }

  • 0
    @ 2017-10-26 00:15:28

    #include <stdio.h>
    int main()
    {
    int N,X;
    int TotalNum = 0;
    int i;
    int Div,Rem;

    scanf("%d %d",&N,&X);

    for (i=1;i<=N;i++)
    {
    Div = i;
    while (Div > 0)
    {
    Rem = Div % 10;
    if (Rem == X)
    {
    TotalNum++;
    }
    Div /= 10;
    }
    }

    printf("%d",TotalNum);

    return 0;
    }

  • 0
    @ 2017-10-19 22:10:14

    #include<iostream>
    using namespace std;
    const int maxn=10000000;
    int n,m,ans;
    int main ()
    {
    cin>>n>>m;
    for (int i=1;i<=n;i++)
    {
    int nn=i;
    while (nn!=0)
    {
    if (nn%10==m) ans++;
    nn/=10;
    }
    }
    cout<<ans;
    }

  • 0
    @ 2017-10-19 13:13:16

    #include<iostream>
    using namespace std;

    void ZT(){
    int n,x,j;
    int m=0;
    cin>>n>>x;
    for(int i=1;i<=n;i++){
    j=i;
    while(j>=1){
    if(j%10==x){
    m++;
    }
    j/=10;
    }
    }
    cout<<m<<endl;
    }

    int main(){
    ZT();
    system("pause");
    return 0;
    }

  • 0
    @ 2017-10-05 23:47:01

    **

  • 0
    @ 2017-10-05 23:01:34

    orz.... 本来今天做题连跪, 找了这个水题做做来提高自信, 写了递交上去居然全wa了, orz....wo擦, 这么水的题居然也跪了, 开始怀疑智商, 想了10几分钟, 没发现哪错了。。。茫然。。。然后没有修改任何地方, 又原原本本的第二次交上去, ma de 怎么又ac了, 什么鬼, 这评测机有问题啊, 太诡异了, 连你都欺负我。。。。。orz看来今天不适合刷题,心累orz
    #include <iostream>
    using namespace std;
    int n, x, sum;

    int search(int c)
    {
    int s = 0;
    while (c != 0)
    {
    if (c % 10 == x)
    ++s;
    c /= 10;
    }
    return s;
    }

    int main()
    {
    cin >> n >> x;
    for (int i = 1; i <= n; ++i)
    {
    sum += search(i);
    }
    cout << sum << endl;
    return 0;
    }

  • 0
    @ 2017-09-30 21:21:39
    n,x=input().split(" ")
    nums2list=list(map(str,list(range(1,int(n)+1))))
    strnums2lst = list("".join(nums2list))
    times=0
    for i in strnums2lst:
        if i == x:
            times+=1
    print(times)
    
  • 0
    @ 2017-09-30 15:59:48
    #include<stdio.h>
    int main()
    {
        int i,n,x,k =0;
        int j;
        scanf("%d %d",&n,&x);
    for(i=1;i<=n;i++)
    {
    j=i;
    while(j)
    {
    if(j%10==x)
    k++;
    j=j/10;
    
    }
    
    }
    printf("%d",k);
    return 0;
    }
    
  • 0
    @ 2017-09-27 21:15:01

    #include <iostream>
    using namespace std;
    int main()
    {
    int i,n,x,k=0,j;
    cin>>n>>x;
    for(i=1;i<=n;i++)
    {
    j=i;
    while(j)
    {
    if(j%10==x)
    k++;
    j=j/10;
    }
    }
    cout<<k;
    return 0;
    }

  • 0
    @ 2017-09-05 21:12:33

    对每一次都取余数

    #include <cstdio>
    
    int n,k,cnt;
    
    int main()
    {
        scanf("%d%d",&n,&k);
        for(int i=1;i<=n;i++)
        {
            int l=i;
            while(l>0)
            {
                if(l%10 == k)
                    cnt++;
                l/=10;
            }
        }
        printf("%d",cnt);
        return 0;
    } 
    
  • 0
    @ 2017-08-15 00:26:21
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    
    int main(){
        int n,a,count=0;
        scanf("%d %d",&n,&a);
        for(int i=1;i<=n;i++) 
        {
            int j=i;
            while(j>=1)
            {
                int t=j%10;
                j=j/10;
                if(t==a)
                    count++;
            }
        }
        printf("%d",count);
        return 0;
    }
    
    
  • 0
    @ 2017-08-14 10:39:28

    干脆的一层层**取余**,对比,适合萌新易理解的代码
    #include <bits/stdc++.h>
    using namespace std;

    int i, n, x, sum = 0, j;

    int main() {
    cin >> n >> x;

    for(i = 1; i <= n; i++) {
    j = i;

    while(j) {
    if(j % 10 == x)

    sum++;

    j = j / 10;

    }
    }

    cout << sum;
    return 0;
    }

  • 0
    @ 2017-08-13 23:14:20

    include "cstdio"

    include "iostream"

    using namespace std;
    int n,x;
    int work(int s)
    {
    int ans=0;
    while(s>=1)
    {
    if(s%10==x)
    ans++;
    s/=10;
    }
    return ans;
    }
    int main()
    {
    int ans=0;
    cin>>n>>x;
    for(int i=1;i<=n;i++)
    ans+=work(i);
    cout<<ans<<endl;
    return 0;
    }

信息

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