Too watery. Feels like a waste of time
topic background
Bessie is half asleep. After a while, she realized she was counting and couldn't sleep.
Topic description
Bessie's brain was very responsive, as if she had actually seen the numbers she had counted. She begins to pay attention to each number (0..9): how many times does each number appear in the counting process?
Given two integers M and N (1 ≤M ≤N ≤2,000,000,000 and NM ≤500,000), find how many times each digit occurs.
For example consider the sequence 129--137: 129, 130, 131, 132, 133, 134, 135, 136, 137. After statistics, it was found that:
0 appears 1 time, 1 appears 10 times, 2 appears 2 times, 3 appears 9 times, 4 appears 1 time, 5 appears 1 time,
6 appears 1 time, 7 appears 1 time, 8 appears 0 times, and 9 appears 1 time.
Input and output format
Input format:
Line 1: Two integers M and N separated by spaces
Output format:
Line 1: Ten integers separated by spaces, each representing the number of times a number (0..9) appears in the sequence.
Input and output example
129 137
1 10 2 9 1 1 1 1 0 1 I
thought it would be very stuck, but it didn't. Then it's boring. The
code is as follows
#include<iostream>
#define ll long long
using namespace std;
int main()
{
int num[10] = { 0 };
ll begin, end;
cin >> begin >> end;
for ( ll i = begin; i <= end; i++)
{
ll d = i;
while (d)
{
num[d % 10]++;
d /= 10;
}
}
for (int i = 0; i < 10; i++)
{
cout << num[i];
if (i + 1 < 10)cout << " ";
}
cout << endl;
return 0;
}