B2082 数字统计 题解
这道题不难,直接循环遍历
#include<bits/stdc++.h>
using namespace std;
int main(){
int l,r,cnt=0;
cin>>l>>r;
for(int i=l;i<=r;i++){
if(i==2){//如果是2就不用判断了
cnt++;
continue;
}
int tmp=i;//把i保存下来,不能直接用,因为这里是循环变量
while(tmp>0){//分解数位
if(tmp%10==2){
cnt++;
}
tmp/=10;
}
}
cout<<cnt;
return 0;
}