算法竞赛入门经典 第三章 uVa1225 - Digit Counting
来源:互联网 发布:婚庆门户源码 编辑:程序博客网 时间:2024/06/02 03:01
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 file 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
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 file 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
#include<iostream>#include<cstring>#include<string>#include<cstdlib>using namespace std;int main(){int n;while (scanf("%d", &n) != EOF){int arr[20][10] = { 0 };int prn;for (int i = 0; i < n; i++){string str;char str1[1000];scanf("%d", &prn);for (int j = 1; j <= prn; j++){sprintf(str1, "%d", j);str += str1;}for (char ch : str){arr[i][ch - '0']++;}}for (int i = 0; i < n; i++){for (int j = 0; j < 10; j++){if (j == 9)printf("%d", arr[i][j]);elseprintf("%d ", arr[i][j]);}printf("\n");}}}
0 0
- 算法竞赛入门经典 第三章 uVa1225 - Digit Counting
- 算法竞赛入门经典(第2版)习题3-3 数数字 Digit Counting UVa1225
- 《算法竞赛入门经典2ndEdition 》习题3-3 数数字(Digit Counting, Uva1225)
- 算法竞赛入门经典 UVa1225数数字
- 算法竞赛入门经典3.3 数数字UVa1225
- 算法竞赛入门经典(刘汝佳)习题3-3 UVa1225
- UVA1225 Digit Counting
- UVA1225 Digit Counting
- uva1225 - Digit Counting
- Digit Counting uva1225
- UVa1225 Digit Counting
- UVa1225 Digit Counting
- UVA1225 UVALive3996 Digit Counting
- UVa1225 Digit Counting
- UVa1225 Digit Counting
- UVa1225 Digit Counting
- UVA1225 Digit Counting
- UVa1225 Digit Counting
- MySQL将多行多列转化为单行单列
- 关于WS_CLIPCHILDREN风格
- java里Date对象格式化为Sun Feb 01 2015格式
- oracle中bulk collect into用法
- tomcat的URIEncoding的作用(转)
- 算法竞赛入门经典 第三章 uVa1225 - Digit Counting
- Vs2013快捷键大全
- webservice中wsdl和soap
- 程序性能优化探讨(4)——直接映射高速缓存命中率问题的模拟
- 软件的MSDN版、OEM版、RTM版有什么不同?
- C语言宏定义
- Oracle读取事件的命名理由
- 动态设置控件的高度和权重
- 冒泡排序