题目:
https://www.luogu.com.cn/problem/P1179
思路:直接暴力过
代码:
#include<iostream>
using namespace std;
int cnt(int x)
{
int sum = 0;
while(x)
{
int temp = x %10;
if(temp == 2)
{
sum++;
}
x = x/10;
}
return sum;
}
int main(void)
{
int L,R;
cin >> L >> R;
int S = 0;
for(int i = L ; i <= R ; i++)
{
S = S + cnt(i);
}
cout << S;
return 0;
}