0 like 0 dislike
1.3k views

Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequence of consecutive integers starting with 1 to N (1 < N < 10000). After that, he counts the number of times each digit (0 to 9) appears in the sequence. For example, with N = 13, the sequence is: 

12345678910111213

In this sequence, 0 appears once, 1 appears 6 times, 2 appears 2 times, 3 appears 3 times, and each digit from 4 to 9 appears once. After playing for a while, Trung gets bored again. He now wants to write a program to do this for him. Your task is to help him with writing this program.
Input:
The input consists of several data sets. The first line of the input file contains the number of data sets which is a positive integer and is not bigger than 20. The following lines describe the data sets. For each test case, there is one single line containing the number N.
Output:
For each test case, write sequentially in one line the number of digit 0, 1, …9 separated by a space.

Sample Input

2
3
13


Sample Output

0 1 1 1 0 0 0 0 0 0
1 6 2 2 1 1 1 1 1 1

Sample Input 2

1
5


Sample Output 2

0 1 1 1 1 1 0 0 0 0
[Normal] Coding (C++) - asked in Introduction to Computer Programming II (C++)
ID: 49740 - Available when: Unlimited - Due to: Unlimited
| 1.3k views

2 Answers

0 like 0 dislike
Hidden content!
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int a[10],b[20];
    int k,n;
** * * ** **** * ** * ***** * ** *
    for(int i=0;i<k;i++)
    {
* * * ** * * * * * * * ** ** * **** * * * * *
* *** ****** *** * * * * *** * * **** ** ***
    }
    for(int i=0;i<k;i++)
    {
* * * *** * * * ****** ** ***** * * **** * ** ** ** ****
* * * ** *** * *** **** * ** * * *** *** * j = 0;j<=b[i];j++)
*** * * ** **** ** *** ** ** * * ******
* *** * * ** ***** ** * * * ***** * * *** * * ** ** *** * * ***** * * k = j;
*** ** * * ** * ** ** * * * ** *** * *** ** * *** * *** **** * **
* * ** ** ** * ** **** ** ** * ** * * * * * * **
* * **** ****** * * * ** ** * * * ** *** ***** *** ** * *** *** * **** ** ******* ** * * ** * num =k%10;
* ****** * * ** *** * ** ** **** * * * **** * *** * *** * *** * *** ** * * * **** *** **
* ***** * * * * * * * ** * * * ***** ** * ***** *** ** ************** * * ***** * ** * **
* *** ** ** ** * * * * ** * *** * * * * ****** ****
** * **** ** * * *** ******* * ** * *****
** * ***** * ** * *** ** * ***** ***** * * *
** * ** * * ** ** * * * *** * ** **** *
** ** * * ** ** * ** * *** ******** *** * ** * * ****
** ** * ** ** **** * ** * *** *** *** *
* * * * * ***** ** ** ** ** * * * * *** * j = 0;j<10;j++)
* ** * ** ******* * ** * *** * ** * ** * ** *
* * * * ***** *** * ** * * ** **** * * ** * * * * ***
**** * * * * * *** * ** **** *** * *** * * * * * * * * ** **** ** * *** * **** * ** ";
** ** * ** ** * **** ****** * ** * *** *** ** ** ** ** * **** * * *** *
* ** * * ** * * * ** ******* **** * **** * * * * * ** *** ** *** *
*** * ** * * ** ** * * * * * ** ****** ** **
    }

    return 0;
}
answered by (-304 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <iostream>

using namespace std;

int main()
{
    int counter[10],counter2[10],arr[1000],arr2[1000];
    int n1,n2,n3,i,j=0,rem,dec,k;
    for(i=0;i<10;i++)
    {
** * ** * * **** ** ** * *** ***** *** ** *
*** *** * * * *** ** *** *** * * * * * ** *** *
** * * ** ***** * ** * ** **** ** * *** * **
    }
    cin >> n1;
    if(n1>1)
    {
** * ** * ** * * * ** * * ** ***** ** * *** *** *** >> n2;
* ** * *** ** * * *** **** * * * ** * * * ** * >> n3;
      
** ** ** * * *** ** ** * * * * * * ** **** *** ** * *** ***
        {
* * * * ** ** * * * * *** * ** ** * * ** ** *
** * ** *** *** * * * *** ** * * * *** * * ** * * ** * ** ** ** *
***** * ** * ** *** * * * * ** * ** ******* * * * ** *** * ***
** ***** ** *** * * * * *** * *** * *** ** ** * ** *** * * ******* * * * *** * *
** ** ** * **** *** *** * * ** ** ** *** * ** * ** ******** * ** ** * * * *** *
** ** * * * **** * * * ** * ******** * ***** * * * * ** * ** *** * ** * * * * *
* *** * * ** * * * ** *** **** * * * ** * *** *** ***** ** **** * ** *** ** ***** *** *** **** * *
**** * * * ** * ** *** * * **** * * * * ** **** ** * * ** ** ** * ** * ** * ** * * ***
****** ** ** **** **** * * * * * * ** *** ***** *** * * * ** ********* * * * * * * ** *
* ** **** ** **** ** **** * * * ** ** * *** **** **** *
        }
* * ** ***** * * * * *** * * * ** ** ** * **
        {
* * * * * ****** ** *** * ** ***** *** *** * * ** ********* ** *** * *
* ** ** ********* * ** * ** * **** * * ****** * **** * **** ** *
* * * **** ******* * * * ** * ** ** * *** ** ** ** ********* * ****** * * ****** * **** * ***** * ** ***
** * *** * *** * **** ** * *** ** ** * ** *** ** * * * * ** * ******* ** * ** ** *** * ** * * * ** * * ** * *** **
** *** * * * **** ** * ** * ** ****** **** ** * ** ******** * **
        }
* ** * * * ****** * * * * * ** * * ****** *** ** ** **** ** *
        {
* ** ** ** * ** * ** * ** * ***** *** * ** ** * ** * ** * ** * * ** **** *
* ** *** * * ****** * * * * * ** * * * **
** * * * * * * ** * * *** * *** ** ** **** **** * **** ** * * * ** ** * **** ******* * ***
* * ***** ***** * ** * * ** * * ** ** ** * * ** * ** * **** * **** * * ** * * *** ** * *** *** ** * ** * *
* * ** ** ** * * *** ** **** ****** ***** *** * ** **** **** *
        }
**** ** **** ** *** * ** *** * * **** * ** *** * ** ***
        {
****** * ** ** ** * ** *** *** * * *** * * ** ** * * **
* *** *** ** * * * * ** * * *** * * * ** * **** ** * * * *** * ** * << counter[i];
* * ** * ***** ** * * ** *** ** * *** * *** * ***** * * * * ** *
** *** ** ** *** ** * ***** * * * * * ***** * *** ** * * * * ** << " " << counter[i];
** ** * ** * * **** ** **** * **** **
* * *** *** * *** * *** * * ** * * ** * * *
**** ** ****** * ****** * ******* ***** *** * *** * ***
* *** * ***** * ****** *** * * * * ** * * ***
** ** * * **** * ** * **** * * *** * * ** ** * * ** * ****** ***
* * ** * ** ** * * * ** * *** * * * **** * ** * * * * * ** * * *** ** << counter2[i];
* * * **** * * * * * **** *** *** ** ** ** ** * * ****
** * * * ** * ** * * * ** *** * * * * * * ** * ** *** ** * << " " << counter2[i];
        }
    }
    else
    {
*** * *** *** * ****** *** * ** ** * * * ** ** ** ***** ** **

* * ******* ** * * * ** *** *** * **** * ** * * *** * ** *
        {
* ** ** * ** * * ** * * ** * * * ****** ***** ** * * * * * *
**** * * * *** *** * *** ** **** * ** ** * * * * * * * * *** * * * * **
* * ******* * ** * * * ** * ** ** ***** * *** * * * ** **
* ** ** * * * *** *** ** * *** * * * * ***** ** * * *** ** * * ** * * *** *** ** *
* * *** * * **** * * **** ** * ** * **** *** **** *** * * **** * * **** * *** * *** ** ** **
* *** **** * **** ** ** ***** ** ** ** ***** *** *** ** ********* ***** * ** * *** ** * *** * * *****
** * * * ** ** * ** **** *** **** * * ** ** **** ***** * ** * ** * *** **** * * *** * **** ****
* *** ***** *** * ***** * * * ** * **** ** * ****** *** * * ** ** **** * ** * * * *
** ** * * * * * * * ** * ** * * **** ** *** * *** *** * ** * * **** ***** *
* ** ******* * * * * *** * * ** ** ** * ** * * ** *** * ** ***
*** * * ** ** * * ***** ** * **** * ***** * *
* * * ******* * * * ** * * * ** * *** * * ** ***
        {
** * ** * * * ** ****** * * ** * ** * * * * ** * * * **** * ** * ** *
* **** ** * * **** *** * *** * * * **** * ** * ****** * * ***** *
* *** * * * * *** *** *** ** * * * ** * * ** * *** * * ** ** ** ***** * ** * ** * ***
* * * * * **** ***** ***** *** ** ***** * * * * * * * ** ** **** * * **** *** * *** ***** ** * * ** * * ***** ** * * **
** ** * * * * ** * **** * * ** * * * * * *** * ** * * *
* * * ** ** * ** ** * * ******** ******
      
* *** ** * ** **** ** * ** * * * * * ***** *
*** * ** ** ****** ** * **** **** * ** **
** ***** * * ** ******** * ****** * * * * * * * **** **
*** ** **** ** **** * ** ***** ** * **** * * * *** * ** * * << counter2[i];
*** * * * *** *** ** **** *** ** ** * * ** * **** **** * * **
* ** * * **** * * *** * * ** * * ** *** * * * * * ** * ** ** << " " << counter2[i];
        }
    }
}
answered by (-323 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 0
Why??
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.130.58
©2016-2025

Related questions

0 like 0 dislike
1 answer
[Normal] Coding (C++) - asked May 17, 2018 in Introduction to Computer Programming II (C++)
ID: 52073 - Available when: Unlimited - Due to: Unlimited
| 861 views
12,783 questions
183,442 answers
172,219 comments
4,824 users