问题描述
小蓝特别喜欢 2,今年是公元 2020 年,他特别高兴。
他很好奇,在公元 1 年到公元 2020 年(包含)中,有多少个年份的数位中包含数字 2?
答案提交
这是一道结果填空的题,你只需要算出结果后提交即可。
本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。
答案:563
题解
模拟:
#include <iostream>
using namespace std;
string s;
int f[210];
bool check(int x)
{
while(x)
{
if(x % 10 == 2) return true;
x /= 10;
}
return false;
}
int main()
{
int ans = 0;
for (int i = 1; i <= 2020; i ++)
if(check(i))
ans ++;
cout << ans << endl;
return 0;
}