Digit Counting UVA - 1225
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的更多相关文章
- UVa 1225 Digit Counting --- 水题
UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...
- UVa1587.Digit Counting
题目连接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=247&p ...
- 数数字 (Digit Counting,ACM/ICPC Danang 2007,UVa 1225)
思路: 利用java 特性,将数字从1 一直加到n,全部放到String中,然后依次对strring扫描每一位,使其carr[str.charAt(i)-'0']++; 最后输出carr[i],即可. ...
- UVa 1225 Digit Counting
题意:给出n,将前n个整数顺次写在一起,统计各个数字出现的次数. 用的最笨的办法--直接统计-- 后来发现网上的题解有先打表来做的 #include<iostream> #include& ...
- UVa 1225 - Digit Counting - ACM/ICPC Danang 2007 解题报告 - C语言
1.题目大意 把前n$(n\le 10000)$个整数顺次写在一起:12345678910111213……计算0~9各出现了多少次. 2.思路 第一想法是打表,然而觉得稍微有点暴力.不过暂时没有想到更 ...
- UVA1225 - Digit Counting(紫书习题3.3)
Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequen ...
- UVa1225 Digit Counting
#include <stdio.h>#include <string.h> int main(){ int T, N, i, j; int a[10]; sc ...
- 数数字(Digit Counting,ACM/ICPC Danang 2007,UVa1225)
#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){ char s[10000]; in ...
- Triangle Counting UVA - 11401(递推)
大白书讲的很好.. #include <iostream> #include <cstring> using namespace std; typedef long long ...
随机推荐
- Python序列之列表(一)
在Python中,列表是一种常用的序列,接下来我来讲一下关于Python中列表的知识. 列表的创建 Python中有多种创建列表的方式 1.使用赋值运算符直接赋值创建列表 在创建列表时,我们直接使用赋 ...
- Vue框架:vue-cookies组件
目录 一.vue-cookies简介 二.vue-cookies安装与配置 三.vue-cookies的使用 一.vue-cookies简介 vue-cookies组件是vue框架用来操作浏览器coo ...
- Linux就该这样学--之常用linux命令及bash基础
Linux就该这样学--之常用linux命令及bash基础 Linux命令 管道 重定向 环境变量 常用命令 常用系统工作命令 系统状态检测命令 工作目录切换命令 文本文件编辑命令 文件目录管理命令 ...
- Docker镜像构建原理解析(不装docker也能构建镜像)
在devops流程里面 构建镜像是一个非常重要的过程,一般构建镜像是写dockerfile文件然后通过docker client来构建的image. docker client 会先检查本地有没有im ...
- 分布式文件系统FastDFS简介、搭建、与SpringBoot整合实现图片上传
之前大学时搭建过一个FastDFS的图片服务器,当时只是抱着好奇的态度搭着玩一下,当时搭建采用了一台虚拟机,tracker和storage服务在一台机器上放着,最近翻之前的博客突然想着在两台机器上搭建 ...
- C++类的友元机制说明
下面给出C++类的友元机制说明(对类private.protected成员访问),需要注意的是,友元机制尽量不用或者少用,虽然它会提供某种程度的效率,但会带来数据安全性的问题. 类的友元 友元是C++ ...
- 第01章-Java SE8的流库
从迭代到流的操作 流表面上看起来和集合很类似,都可以让我们转换和获取数据,但是它们之间存在着显著的差异 流并不存储其元素,这些元素可能存储在底层的集合中,或者是按需生成的 流的操作不会修改其数据源 流 ...
- 【DB宝42】MySQL高可用架构MHA+ProxySQL实现读写分离和负载均衡
目录 一.MHA+ProxySQL架构 二.快速搭建MHA环境 2.1 下载MHA镜像 2.2 编辑yml文件,创建MHA相关容器 2.3 安装docker-compose软件(若已安装,可忽略) 2 ...
- locust工具使用详解
今年负责部门的人员培养工作,最近在部门内部分享和讲解了locust这个工具,今天再博客园记录下培训细节 一.简介 1.优势 locust是python语言开发的一款的开源的的性能测试框架,他比jmet ...
- slickgrid ( nsunleo-slickgrid ) 4 解决点击不切换单元格的问题
slickgrid ( nsunleo-slickgrid ) 4 解决点击不切换单元格的问题 上一次解决了列选择和区域选择冲突的问题,昨天太忙了,并且要陪小宝早点睡觉,就啥也没有赶上.今天上班面试. ...