[2010年NOIP普及组] 数字统计
统计指定数字出现的次数。
#include<iostream>
using namespace std;
int check(int n)
{
int f;
int i = 0;
while (n >= 10)
{
f = n % 10;
n /= 10;
if (f == 2)
{
i++;
}
}
if (n == 2)
{
i++;
}
return i;
}
int main()
{
int n, m;
int ans = 0;
cin >> n >> m;
for (int i = n; i <= m; i++)
{
ans += check(i);
}
cout << ans << endl;
return 0;
}