题目链接
题解
枚举n-m的所有数字.
然后判断统计答案就好了.
循环嵌套裸题.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> using namespace std ; template<class T>void read(T &x){ x=0;int f=0;char ch=getchar(); while(ch<'0'||ch>'9'){f|=(ch=='-');ch=getchar();} while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} x=f?-x:x; return ; } int main() { int n,m,ans=0;read(n),read(m); for(int i=n;i<=m;i++){ int x=i; while(x){ int g=x%10; if(g==2) ans++; x/=10; } } printf("%d",ans); return 0; } |
By:Wahacer
2017.11.23
23:45