​   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
1 6 2 2 1 1 1 1 1 1

HINT

直接暴力破解~

Accepted

#include<stdio.h>
#include<string.h> int main()
{
int sum;
scanf("%d", &sum);
while (sum--)
{
int num;
int arr[10] = { 0 };
scanf("%d", &num);
for (int i = 1;i <= num;i++)
{
int a, b;
a = i;
while (a)
{
b = a % 10;
a /= 10;
arr[b]++;
}
}
for (int i = 0;i < 9;i++)
printf("%d ", arr[i]);
printf("%d\n", arr[9]);
}
}

Digit Counting UVA - 1225的更多相关文章

  1. UVa 1225 Digit Counting --- 水题

    UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...

  2. UVa1587.Digit Counting

    题目连接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=247&p ...

  3. 数数字 (Digit Counting,ACM/ICPC Danang 2007,UVa 1225)

    思路: 利用java 特性,将数字从1 一直加到n,全部放到String中,然后依次对strring扫描每一位,使其carr[str.charAt(i)-'0']++; 最后输出carr[i],即可. ...

  4. UVa 1225 Digit Counting

    题意:给出n,将前n个整数顺次写在一起,统计各个数字出现的次数. 用的最笨的办法--直接统计-- 后来发现网上的题解有先打表来做的 #include<iostream> #include& ...

  5. UVa 1225 - Digit Counting - ACM/ICPC Danang 2007 解题报告 - C语言

    1.题目大意 把前n$(n\le 10000)$个整数顺次写在一起:12345678910111213……计算0~9各出现了多少次. 2.思路 第一想法是打表,然而觉得稍微有点暴力.不过暂时没有想到更 ...

  6. UVA1225 - Digit Counting(紫书习题3.3)

    Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequen ...

  7. UVa1225 Digit Counting

    #include <stdio.h>#include <string.h> int main(){    int T, N, i, j;    int a[10];    sc ...

  8. 数数字(Digit Counting,ACM/ICPC Danang 2007,UVa1225)

    #include<stdio.h>#include<stdlib.h>#include<string.h>int main(){ char s[10000]; in ...

  9. Triangle Counting UVA - 11401(递推)

    大白书讲的很好.. #include <iostream> #include <cstring> using namespace std; typedef long long ...

随机推荐

  1. idea配置阿里maven镜像

    首先打开IDEA安装路径下的:"\plugins\maven\lib\maven3\conf\settings.xml" 找到里面的mirror配置,进行修改如下: <mir ...

  2. eclipse输入时自动提示

    当输入一部分代码时,其他的候选代码提示出来,可以提高开发的效率,设置方法如下: 选择Window -> Perferences -> Java -> Editor -> Con ...

  3. 求幂&&快速幂&&位运算

    1.普通的求幂方法: 时间复杂度为O(n),对于比较大的数在1s限时内可能会TLE int pow(int base,int p){ int ans=1; for(int i=1;i<=p;i+ ...

  4. Linux 安装python 模块及库

    转载于https://blog.csdn.net/csdn_am/article/details/79924744 有时我们使用下载python 自带的pip 安装一些工具包时,会报如下错误 找不到满 ...

  5. MySQL:多表查询

    SELECT查询不但可以从一张表查询数据,还可以从多张表同时查询数据.查询多张表的语法是:SELECT * FROM <表1> <表2>,普通多表查询会获取M x N行记录,所 ...

  6. MySQL注入 前端int型参数插入SQL语句

    类似PHP语言的 mysql_real_escape_string() 的函数,在用来防范SQL注入的时候,可能会遇到int型注入成功的情况. mysql_real_escape_string()用法 ...

  7. POJ-3660(Floyd算法)

    Cow Contest POJ-3660 1.本题考察的是最短路,用的算法是Floyd算法 2.如果一个结点和剩余的n-1个结点都有关系,那么可以确定其排名 3.需要注意的是,判断是否有关系时,反向关 ...

  8. CCF(公共钥匙盒):思维+模拟

    公共钥匙盒 201709-2 这题的思路一开始不是很清晰,一开始想用贪心去做.但是发现按照题目的思路不对.所以这里采用的是类似于多项式的加减的处理. #include<iostream> ...

  9. three.js cannon.js物理引擎之齿轮动画

    郭先生今天继续说一说cannon.js物理引擎,并用之前已经学习过的知识实现一个小动画,知识点包括ConvexPolyhedron多边形.Shape几何体.Body刚体.HingeConstraint ...

  10. MySQL深入研究--学习总结(3)

    前言 接上文,继续学习后续章节.细心的同学已经发现,我整理的并不一定是作者讲的内容,更多是结合自己的理解,加以阐述,所以建议结合原文一起理解. 第九章<普通索引和唯一索引,如何选择> 从查 ...