4315. Digit Count

 

                                 4315. Digit Count
 
 
Total:526Accepted:228Rating:
2.0/5.0(2 votes)
 
   

   
 
Time Limit: 1sec    Memory Limit:256MB
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
Copy sample input to clipboard
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

 

 

// 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;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值