题解 | #[NOIP2010]数字统计#
[NOIP2010]数字统计
https://www.nowcoder.com/practice/179d9754eeaf48a1b9a49dc1d438525a
#include <iostream>
using namespace std;
int main() {
int a = 0, b = 0;
scanf("%d %d", &a, &b);
//printf("%d %d", a, b);
int count = 0;
for (int j = a; j <= b; j++) {
int i = j;//这里要注意用个临时变量进行运算
while(i)
{
//cout <<'c'<< i << " ";
if(i % 10 == 2)
{
count++;
}
i = i / 10;
//cout << "b"<< i << " ";
}
//cout<< " ccc" << endl;
}
cout << count;
return 0;
}
// 64 位输出请用 printf("%lld")