cggwz  

题目链接:数字统计
这题很水。
思路就是:枚举每一个区间内的数,然后对于每一个数,每个位去判断是否为2,就行了。
下面上代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int l,r;
    scanf("%d%d",&l,&r);
    int ans=0;
    for(int i=l;i<=r;i++){
        int x=i;
        while(x>0){
            int cur=x%10;
            if(cur==2){
                ans++;
            }
            x/=10;
        }
    }
    printf("%d",ans);
    return 0;
}

什么也不想讲。

posted on 2017-08-23 23:18  cggwz  阅读(208)  评论(0)    收藏  举报