题解
2026-04-04 18:07:59
发布于:上海
21阅读
0回复
0点赞
通过模10找个位,如果是2,cnt++,最后判断是否刚好有三个2
#include<cstdio>
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,cnt=0;//cnt记录2的数量
while(x>0){
if(x%10==2)cnt++;
x/=10;
}
if(cnt==3)ans++;
}
printf("%d",ans);
return 0;
}
这里空空如也




有帮助,赞一个