博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【UVA】 1225 --- Digit Counting
阅读量:2039 次
发布时间:2019-04-28

本文共 1583 字,大约阅读时间需要 5 分钟。

【UVA】 1225 --- Digit Counting

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) 个整数顺次写在一起: 123456789101112…数一数0~ 9各出现多少次
( 输出10个整数, 分别是0, 1, …, 9出现的次数) 。

#include 
using namespace std;int main(){
int n; cin >> n; while (n--) {
int arr[10]{
0 }; int m; cin >> m; for (int i = 1; i <= m; i++) {
int x = i; while (x) {
arr[x % 10]++; x /= 10; } } for (int i = 0; i < 10; i++) {
if (i == 9) {
cout << arr[i] << endl; } else {
cout << arr[i] << " "; } } } return 0;}

转载地址:http://wwfof.baihongyu.com/

你可能感兴趣的文章
微软技术节(TechFest 2010)最前沿技术汇总
查看>>
SQL 操作结果集 -并集、差集、交集、结果集排序
查看>>
详解索引连接类型
查看>>
托管堆与垃圾收集
查看>>
MySQL初夜(乱码问题,命令行客户端使用)
查看>>
jQuery工具函数
查看>>
cookie
查看>>
javascript之window对象
查看>>
HttpCookie类
查看>>
(转载addone)完全使用Linux作为桌面系统 —— 使用Linux两年记 --软件列表
查看>>
wxzh001,进来看关于APACHE+PHP+MYSQL+SSL的LINUX下安装配置(转自奥索)
查看>>
google app api相关(商用)
查看>>
linux放音乐cd
查看>>
开源im方案之openfire
查看>>
OneNote无法同步问题
查看>>
GridView选择性导出Excel
查看>>
GridView+存储过程实现'真分页'
查看>>
HTML5-认识篇
查看>>
Web Service(一):Hello World
查看>>
开启 J2EE(二)— JDBC
查看>>