英文

Description

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

中文

题目大意:

把前n(n<=10000)个整数顺次写在一起,如n=15时,123456789101112131415
计算0-9各出现了多少次(输出10个数,分别是数字0-9出现的次数)

提示:

写一个子程序来累加一个数中每个数字的出现个数就行了。小心UVa中莫名其妙的格式错误。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
long long a[11],n,T;
void pro(long long k)
{while(k>0){a[k%10]++;k/=10;}
}
int main()
{scanf("%lld",&T);for(int i=1;i<=T;i++){memset(a,0,sizeof(a));scanf("%lld",&n);for(int j=1;j<=n;j++) pro(j);for(int j=0;j<=8;j++) printf("%lld ",a[j]);printf("%lld\n",a[9]);}return 0;
}

相关链接:

UVa题解小全:
https://blog.csdn.net/zj_mrz/article/details/81144019

UVa 1583 Digit Generator 生成元 题解:
https://blog.csdn.net/zj_mrz/article/details/81143855

UVa 1585 Score 得分 题解:
https://blog.csdn.net/zj_mrz/article/details/81144159

转载于:https://www.cnblogs.com/zj-mrz/p/10122457.html

UVa 1225 Digit Counting 题解相关推荐

  1. UVa 1225 Digit Counting

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

  2. UVA - 1225 Digit Counting(刘汝佳紫书题单(算法竞赛入门经典 第二版 2014)

    个人感觉这道题有表述问题 他的题目表述说明测试数据中的数是不超过20的,但其实他的测试点中是有百位数的,所以按两位数去处理数据显然会造成数组越界. 代码如下 #include <bits/std ...

  3. 感觉自己做这个题的思路很不错 1225 Digit Counting

    这是代码 #include<stdio.h> #include<string.h> main() {int m,i,l,qian2[10],x,y;scanf("%d ...

  4. UVA1225 ​​​​​​​Digit Counting

    Digit Counting UVA - 1225 题目传送门 题目大意:输入一个数字T,代表有T组测试数据,下面每行有一个整数n,求将1到n的数字连成一串后每个数字出现的个数. AC代码: #inc ...

  5. UVa1225 - Digit Counting

    //UVa1225 - Digit Counting //题目:输出1~N所有数字中,统计0~9出现的总次数. //已AC #include<stdio.h> #include<st ...

  6. UVA - 1225

    UVA - 1225 穷举法: #include <bits/stdc++.h> using namespace std; int main(){int T;cin>>T;in ...

  7. 算法入门竞赛习题3-3:数数字(Digit Counting) 把前n(n≤10000)个整数顺次写在一起:123456789101112…数一数0~9各出现多少次。

    算法入门竞赛习题 习题3-3:数数字(Digit Counting) 把前n(n≤10000)个整数顺次写在一起:123456789101112-数一数0-9各出现多少次 (输出10个整数,分别是0, ...

  8. CodeChef Chef and Digit Jumps 题解

    原题链接:Chef and Digit Jumps 题意:原题中有链接. 题解:一道很明显的bfs题,就是跳就可以了,当然,跳的时候可以加一些优化,具体看代码 #include <queue&g ...

  9. UVA 11401 Triangle Counting(详解)

    Triangle Counting 分析一下 以八为例子 1 2 3 4 5 6 7 8 以(7,8)为边,就有6 7 8, 5 7 8, 4 7 8 ,3 7 8 ,2 7 8 五种情况: 以(6, ...

最新文章

  1. 数据中心冷却水系统的一种节能优化控制策略
  2. dedecms的自定义模块
  3. 猛增 174K Star!前端最流行的 10 大顶级开源项目!
  4. android开发之shape详解
  5. left join、right join、inner join的区别
  6. Freezer - 备份云硬盘实现
  7. 数列分块入门 9(LibreOj-6285)
  8. 现实问题从数学化到离散化再到程序化
  9. 5G 时代,一加的机会在哪里?
  10. 网站小图标制作及配置
  11. UWB定位系统上位机源码
  12. CentOS7安装Teamviewer
  13. 微信小程序“errMsg“:“openSetting:fail can only be invoked by user TAP gesture.“
  14. android 开机动画实现,Android App启动画面实现
  15. 计算机三级考点6:网络关键设备选型。
  16. 51单片机控制二相四线步进电机
  17. 单点登录、域用户、常规登录、AD域
  18. 智慧城市App解决方案
  19. P2P行业产品经理的分析
  20. 大唐杯学习笔记(1)---5G网络架构和组网部署

热门文章

  1. Linux Shell基础 - Shell 脚本的执行方式
  2. [BAT] 执行xcopy命令后出现Invalid num of parameters错误的解决办法
  3. linux网络配置、ssh、scp及命令优先级作业
  4. 喵哈哈村的魔法考试 Round #1 (Div.2) C 喵哈哈村的魔法石(II) 背包dp
  5. 南通大学教务管理微信体验
  6. 代码的抽象三原则【转载】
  7. [Erlang危机](4.4)命名管道
  8. ASP.NET - Eval使用自定义的方法
  9. fglrx 9.8与kernel 2.6.30
  10. uniapp路由传多个参数_2020年家用路由器购买推荐(20200921更新)