NOIP普及组 数字统计
考点
- 搜索
- 字符串
水题,只做展示
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int l,r;
int main()
{
int tmp,cnt=0;
scanf("%d%d",&l,&r);
for(int i=l;i<=r;++i)
{
tmp=i;
while(tmp)
{
if(tmp%10==2)
{
++cnt;
}
tmp/=10;
}
}
printf("%d\n",cnt);
}