P1554 dream statistics, P1554 dream statistics
Background
Bessie is half-awake. After a while, she realized that she was counting and could not fall asleep.
Description
Bessie's brain is responsive, as if to see one number after another. She began to pay attention to every digital number (0 .. 9): How many times did each digital number appear in the counting process?
Given two integers M and N (1 ≤ M ≤ N ≤ 2,000,000,000 and N-M ≤ 500,000), find how many times each digital appear.
For example, the sequence 129,130,131,132,133,134,135,136,137-is considered. Statistics show that:
0 appears once, 1 appears 10 times, 2 appears 2 times, 3 appears 9 times, 4 appears once, 5 appears once,
6 appears once, 7 appears once, 8 appears 0, 9 appears once.
Input/Output Format
Input Format:
Row 1st: two integers M and N separated by Spaces
Output Format:
Row 1st: Ten integers separated by spaces, indicating the number of times a number (0 .. 9) appears in the sequence.
Input and Output sample input sample #1:
129 137
Output sample #1:
1 10 2 9 1 1 1 1 0 1
Enable scalping mode 23333
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<map> 6 #include<algorithm> 7 #define LL long long int 8 using namespace std; 9 const int MAXN=88000;10 inline void read(int &n)11 {12 char c=getchar();n=0;bool flag=0;13 while(c<'0'||c>'9') c=='-'?flag=1,c=getchar():c=getchar();14 while(c>='0'&&c<='9') n=n*10+c-48,c=getchar();flag==1?n=-n:n=n;15 }16 LL n,m;17 LL ans[10];18 int main()19 {20 // read(n);read(m);21 cin>>n>>m;22 for(LL i=n;i<=m;i++)23 {24 LL p=i;25 while(p)26 {27 ans[p%10]++,28 p/=10;29 }30 }31 for(int i=0;i<=9;i++)32 printf("%lld ",ans[i]);33 return 0;34 }