文章

15

粉丝

27

获赞

0

访问

1.9k

头像
数字统计 题解:转string暴力破
P1002 兰州大学机试题
发布于2024年4月3日 09:51
阅读数 100

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

int main(){
	int l,r;
	while(cin>>l>>r){
		int ans=0;
		for(int i=l;i<=r;i++){
			string s=to_string(i);
			for(int j=0;j<s.size();j++){
				if(s[j]=='2')ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发