文章

246

粉丝

0

获赞

1171

访问

55.9k

头像
数字统计 题解:
P1002 兰州大学机试题
发布于2026年1月29日 21:38
阅读数 323

#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;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发