数字统计
直接枚举
#include<iostream>
using namespace std;
int l,r;
int count(int n)
{
int sum = 0;
while(n)
{
if(n%10 == 2) sum ++;
n = n/10;
}
return sum;
}
int main()
{
scanf("%d%d",&l,&r);
int res = 0;
for(int i = l;i <= r;i ++) res += count(i);
printf("%d",res);
}