美丽的2
题目 美丽的2
思路分析
直接枚举1~2020 对每个数进行拆分 老朋友了
代码实现
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int cnt=0;
for(int i=1;i<=2020;i++){
int x=i;
bool flag=false;
while(x){
if(x%10==2)
flag=true;
x/=10;
}
if(flag)
cnt++;
}
cout<<cnt;
return 0;
}
同类题型
视频讲解
⬅️ 第十一届蓝桥杯大赛软件赛决赛C/C++ 大学 B 组 🏠 00-冲刺国赛 ➡️ 扩散
💬 评论