文章

19

粉丝

0

获赞

57

访问

1.7k

头像
数字统计 题解:
P1002 兰州大学机试题
发布于2026年3月18日 20:57
阅读数 56

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

int counttwo(int x){
    int ans = 0;
    string s = to_string(x);
    for(int i=0;i<s.size();i++){
        if(s[i]=='2'){
            ans++;
        }
    }
    return ans;
}

int main(){
    int m,n;
    while(cin >> m >>n){
        int count = 0;
        for(int i=m;i<=n;i++){
                int temp = counttwo(i);
                count += temp;
        }
        cout << count << endl;
    }    
    return...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发