(第一题)数字统计【洛谷】P1179

题目大意

给两个整数L,R(1<=L,R<=1000000),求出数字2在此区间出现过几次

分析

数据不大,模拟AC

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int L,R,ans=0;
	scanf("%d%d",&L,&R);
	for(int i=L;i<=R;i++)
	{
		char c[10]={' '};
		sprintf(c,"%d",i);
		string s=c;
		for(int j=0;j<s.size();j++)
		 if(s[j]=='2')
		  ans++;
	}
	printf("%d",ans);
}

猜你喜欢

转载自blog.csdn.net/qq_43034907/article/details/82939632
今日推荐