C++代码
#include<iostream>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
int cnt = 0;
for(int i = n; i <= m; i++)
{
int x = i;
while(x)
{
if(x % 10 == 2) cnt ++;
x = x / 10;
}
}
cout << cnt << endl;
return 0;
}