[GESP2603二级] 数数

枚举所有数字并筛选统计

数字拆分+累计

#include <bits/stdc++.h>
using namespace std;
int main(){
    int l,r;
    cin>>l>>r;
    int cnt=0;
    for(int i=l;i<=r;i++){
        int j=i;
        int t=0;
        while(j){
            t+=j%10==2;
            j/=10;
        }
        if(t==3) cnt++;
    }
    cout<<cnt;
    return 0;
}