每日刷题(116)
美丽的 2
题目描述
本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。
C++题解
#include<bits/stdc++.h>
using namespace std;
bool isTwo(int year)
{
int flag = 0;
while(year)
{
if(year % 10 == 2)
{
flag = 1;
return true;
}
year /= 10;
}
return false;
}
int main()
{
int ans = 0;
for(int i = 2; i <= 2020; i += 1)
{
if(isTwo(i))
{
ans++;
}
}
cout << ans << endl;
return 0;
}
所以答案是563