题目链接:精选项目课程_IT热门课程_蓝桥云课课程 - 蓝桥云课
答案:624
题目解析:根据题目要求编码即可
代码:
//#define local
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
int n;
// 计算数n含有多少个2
ll count(int n){
ll res=0;
for(int i=1;i<=n;i++){
int t=i;
while(t){
if(t%10==2)
res++;
t=t/10;
}
}
return res;
}
int main(){
#ifdef local
//freopen("data.in","rb",stdin);
//freopen("data.out","wb",stdout);
#endif
scanf("%d",&n);
cout<<count(n);
return 0;
}