9 solutions
-
0
#include<bits/stdc++.h> using namespace std; int l,r,cnt;//l,r:l-r之间的范围 int sum(int x){//这个函数的意义:判断2出现的次数 int cnt=0; while(x>0){//检查各个位数上有没有2 if(x%10==2) cnt++;//检查个位 x/=10;//去掉个位,再提取个位判断,直到x=0,停止判断 } return cnt;//返回cnt } int main(){ cin>>l>>r; for(int i=l;i<=r;i++){ cnt+=sum(i);//将这个范围内2出现的次数累加 } cout<<cnt;//输出 return 0; }
- 1
Information
- ID
- 488
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 3
- Tags
- # Submissions
- 141
- Accepted
- 76
- Uploaded By