Description
For an integer N, you can write 1 to N in one line. For example, when N=12, the number from 1 to N written in a line, we can get a new string: 123456789101112 There are one '0', five '1', two '2', ..., one '9' in the new string. Your task is very easy, for a given N, tell me how many '0','1','2',...,'8','9' in the new string which write down from 1 to N?
Input
The first line contains an integer T (1<=T<=10), indicating the number of test cases. Then, for each case, there is only a number N (1<=N<=1000).
Output
One line for each case, print the number of '0','1','2',...,'8','9', separated by a space.
Sample Input
2 12 5
Sample Output
1 5 2 1 1 1 1 1 1 1 0 1 1 1 1 1 0 0 0 0 |
4315. Digit Count
| |||||||||
| |||||||||
// source code of submission 1030299, Zhongshan University Online Judge System
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int a,n;
cin >> n;
while (n--)
{
vector<int>arr;
int result[10]= {0};
cin >> a;
for(int i = 1;i <= a; i++)
{
if(i < 10)
arr.push_back(i);
else if(i < 100)
{
arr.push_back(i/10);
arr.push_back(i%10);
}
else if(i < 1000)
{
arr.push_back(i/100);
arr.push_back((i/10)%10);
arr.push_back(i%10);
}
else
{
arr.push_back(1);
arr.push_back(0);
arr.push_back(0);
arr.push_back(0);
}
}
for(int j = 0; j < arr.size(); j++ )
{
for(int k = 0; k <= 9; k++)
{
if(arr[j] == k)
result[k]++;
}
}
for(int k = 0; k <= 8; k++)
{
cout << result[k] << " ";
}
cout << result[9] << endl;
}
return 0;
}