题解

60 条题解

  • 1
    @ 2021-08-30 09:53:25
    #include<iostream>
    using namespace std;
    int main()
    {
        long long a,b,s=0,n;
        cin>>a>>b;
        for(int y=a;y<=b;y++)
        {
            n=y;
            while(n!=0)
            {
                if(n%10==2) s++;
                n/=10;
            }
        }
        cout<<s;
            return 0;
    }
    
  • 1
    @ 2021-02-21 19:28:17
    #include<iostream>
    using namespace std;
    int main()//水题+动态数组
    {
        int min,max;cin>>min>>max;
        int *a;
        a=new int [10001];
        int cnt=0;
        for(int i=min;i<=max;i++)
        {
            int j=i;
            int d;
            while(j>0)
            {
                d=j%10;
                j/=10;
                if(d==2) cnt++;
                d=0;
            }
        }   
        cout<<cnt;
        return 0;
    }
    
  • 1
    @ 2018-08-08 19:11:56

    var
    n,t,l,k,num,i:longint;
    s,num1:string;
    begin
    read(n,num);
    str(2,num1);
    for i:=n to num do
    begin
    str(i,s);
    k:=length(s);
    l:=0;
    while l<k do
    begin
    inc(l);
    if s[l]=num1 then inc(t);
    end;
    end;
    write(t);
    end.
    哎呀,空大了!!!

  • 1
    @ 2018-02-06 10:12:13
    #include <stdio.h>
    int a[10];
    int main(){
        int n,m;
        scanf("%d%d", &m, &n);
        for(int i=m; i<=n; i++){
            int k=i;
            while(k){
                a[k%10]++;
                k/=10;
            }
        }
        printf("%d", a[2]);
        return 0;
    }
    
  • 1
    @ 2017-11-08 13:37:21

    水题不解释

    #include<iostream>
    using namespace std;
    int l,r,ans;
    int main()
    {
        cin>>l>>r;
        for(int i=l;i<=r;i++)
        {
            int a=i;
            while(a>0)
            {
                if(a%10==2) ans++;
                a/=10;
            }
        }
        cout<<ans;
        return 0;
    }
    
  • 1
    @ 2017-09-19 23:42:20

    纯水

    #include<iostream>
    using namespace std;
    int main()
    {
        int l,r,i,ans=0,x;
        cin>>l>>r;
        for(i=l;i<=r;i++)
        {
            x=i;
            while(x>0)
            {
                if(x%10==2)
                ans++;
                x/=10;
            }
        }
        cout<<ans;
        return 0;
    } 
    
  • 1
    @ 2017-09-07 22:09:33
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<vector>
    #include<math.h>
    
    using namespace std;
    
    vector<int> w;
    
    void f(int a){
        while (a>0){
            w.push_back(a%10);
            a/=10;
        }
    }
    
    int main(void){
        //freopen("1.in","r",stdin);
        //freopen("1.out","w",stdout);
        int l,r;
        cin>>l>>r;
        for (int i=l;i<=r;i++){
            f(i);
        }
        int ans=0;
        for (int i=0;i<w.size();i++){
            if (w[i]==2) ans++;
        }
        cout<<ans;
    }
    

    waterful

  • 1
    @ 2017-08-24 00:47:09

    so water 暴搜即可!!!!!!!!!!!!!!!!!

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    int main()
    {
        long long n,all=0,a,i;
        scanf("%lld %lld",&a,&n);
        for(i=a;i<=n;i++)
        {
            long long aha=i;
            while(aha>=1)
            {
                if(aha%10==2)
                    all++;
                aha=aha/10;
            }
        }
        printf("%lld",all);
        return 0;
    }
    
  • 1
    @ 2017-04-21 20:25:21

    题目很简单,方法步骤如下:
    1. 输入两个数(范围)
    2. 创造循环每个数,比较有没有“2”
    3. 把“2”的数量算出来

    注意:
    * 因为题目要求是范围在10000,(1≤L≤R≤10000)
    * 所以只要比较到万位
    * 将每个位的数进行判断,凡有一个次数就加1

    代码如下

    #include<stdio.h>
    int main()
    {
        int sum=0;
        int a;
        int b;
        int x;
        scanf("%d %d",&a,&b);
        for(x=a;x<=b;x++)
        {
            if((x/1)%10==2)//个位 
            sum++;
            if((x/10)%10==2)//十位 
            sum++;
            if((x/100)%10==2)//百位
            sum++;
            if((x/1000)%10==2)//千位 
            sum++;
            if((x/10000)%10==2)//万位 
            sum++;
        }
        printf("%d",sum); 
    } 
    
  • 0
    @ 2018-10-05 00:36:39

    直接字符吧
    #include<bits/stdc++.h>
    using namespace std;
    char s[10];
    int main()
    {

    int l,r,ans=0;
    cin>>l>>r;
    for(int i=l;i<=r;i++)
    {
    sprintf(s,"%d",i);
    l=strlen(s);
    for(int j=0;j<=l-1;j++)
    if(s[j]=='2')
    ans++;
    }
    cout<<ans;
    }

  • 0
    @ 2018-03-05 13:30:15

    #include<iostream>
    #include<cmath>
    using namespace std;
    int main()
    {
    int l,r,a,num=0;
    cin>>l>>r;
    for (int i=l;i<=r;i++)
    {
    if (2==i/10000) num+=1;
    if (2==(i%10000)/1000) num+=1;
    if (2==(i%1000)/100) num+=1;
    if (2==(i%100)/10) num+=1;
    if (2==i%10) num+=1;
    }
    cout<<num;
    return 0;
    }

  • 0
    @ 2018-02-03 11:35:00

    自定义函数
    #include<bits/stdc++.h>
    using namespace std;
    int js(int n){
    int x,s=0;
    while(n>=1){
    x=n;
    x=x%10;
    n=n/10;
    if(x==2)
    s++;
    }
    return s;
    }
    int main(){
    int l,r,s=0,i;
    cin>>l>>r;
    for(i=l;i<=r;i++)

    s+=js(i);
    cout<<s;
    return 0;
    }

  • 0
    @ 2017-10-28 18:03:09

    三分钟AC,纯属练手

    #include<iostream>
    #include<cstring>
    #include<algorithm>
    
    using namespace std;
    
    int a,b;
    
    int main()
    {
        scanf("%d%d",&a,&b);
        int ans=0,u,bt;
        for(int i=a;i<=b;++i)
        {
            u=i;
            while(u>0)
            {
                bt=u%10;
                if(bt==2)ans++;
                u=(u-bt)/10;
            }
        }
        printf("%d",ans);
        return 0;
    } 
    
  • 0
    @ 2017-10-25 17:14:32

    #include<bits/stdc++.h>
    using namespace std;

    int main(){
    int a,b=0,c,d;
    cin>>a>>c;
    for(int i=a;i<=c;i++){
    d=i;
    while(d!=0){
    if(d%10==2){
    b++;
    }
    d=d/10;
    }
    }
    cout<<b<<endl;
    }

  • 0
    @ 2017-07-27 23:00:12

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

    int fj(int x)
    {
    int ans=0,y=x;
    while(y)
    {
    if(y%10==2)
    ans++;
    y/=10;
    }
    return ans;
    }

    int main()
    {
    //freopen("数字统计.in","r",stdin);
    //freopen("数字统计.out","w",stdout);
    int a,b,ans=0;
    scanf("%d%d",&a,&b);
    for(int i=a;i<=b;i++)
    ans+=fj(i);
    printf("%d\n",ans);
    return 0;
    }

  • 0
    @ 2017-07-22 17:21:44

    #include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <algorithm>
    using namespace std;
    int main()
    {
    int l,r,x,s=0;
    scanf("%d%d",&l,&r);
    for(int i=l;i<=r;i++)
    {
    x=i;
    while(x>0)
    {
    if(x%10==2)
    {
    s++;
    }
    x=x/10;
    }
    }
    printf("%d\n",s);
    return 0;
    }

  • 0
    @ 2017-07-02 21:10:58

    算法很简单,只需要判断这两个数范围内每个数,将范围内每个数的各个位的数分离出来,如果分离出来的各个数中有一个数为2,就使计数器加一,最后输出这个计数器就好。

    #include<stdio.h>
    int main(){
    int L,R;
    scanf("%d %d",&L,&R);
    int n=0;
    for(;L<=R;L++)
    {
    if((L/1000)==2)
    n++;
    if((((L/100)>10)?((L/100)-10*(L/1000)):(L/100))==2)
    n++;
    if((((L/10)>10)?((L/10)-10*(L/100)):(L/10))==2)
    n++;
    if(L%10==2)
    n++;
    }

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

  • 0
    @ 2016-10-31 17:31:57

    水数据!水题!

  • 0
    @ 2016-10-31 17:31:26

    var n,m,i,j,h:longint;
    a:array[1..100000] of string;
    begin
    read(n,m);
    for i:=n to m do
    str(i,a[i]);
    for i:=1 to m do
    if a[i]='' then a[i]:='LYY';
    i:=0;
    repeat
    inc(i);
    for j:=1 to 20 do
    if a[i][j]='2' then inc (h);
    until a[i]='';
    write(h);
    end.

  • 0
    @ 2016-10-16 10:15:55
    #include<iostream>
    using namespace std;
    int main()
    {
        int l, r, count = 0;
        cin >> l >> r;
        for(int i = l ; i <= r; i++)
        {
            int t = i;
            while(t != 0)
            {
                if(t % 10 == 2)
                    count ++;
                t /= 10;
            }
        }
        cout << count << endl;
        return 0;
    }
    
    

信息

ID
1784
难度
2
分类
模拟 点击显示
标签
递交数
2761
已通过
1662
通过率
60%
被复制
19
上传者