数字统计 题解:
#include<iostream>
using namespace std;
int get(int x)
{
int cnt=0;
string s=to_string(x);
for(int i=0;i<s.size();i++)
if(s[i]=='2')
cnt++;
return cnt;
}
int main()
{
int l,r;
while(cin>>l>>r)
{
int res=0;
for(int i=l;i<=r;i++)
res+=get(i);
cout<<res<<endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发