P1554 dream statistics, P1554 dream statistics

Source: Internet
Author: User

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 }

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.