#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")