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

13764622 1225 Digit Counting Accepted C++11 0.035 2014-06-18 07:44:02

1225 - Digit Counting

Time limit: 3.000 seconds

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,然后会 123456789……N 这么一个数,算出其中0~9数字出现的个数。
解题思路:题目不难,字符串处理就能轻松解决。主意输出不要有多的空格就ok。
 #include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
using namespace std; int main() {
int l, maxx_int; cin >> l;
string maxx_str;
int tab[];
while(l--) {
cin >> maxx_int;
memset(tab, , sizeof(tab));
for(int i = ; i <= maxx_int; i++) {
stringstream ss;
ss << i; ss >> maxx_str;
for(int j = ; j < maxx_str.size(); j++) {
tab[maxx_str[j] - ''] ++;
}
}
for(int i = ; i < ; i++) {
if(i == ) {
cout << tab[i];
} else { cout << " " << tab[i];
}
}
cout << endl;
//cout << maxx_str << endl;
}
return ;
}

AC代码

UVa1587.Digit Counting的更多相关文章

  1. UVa 1225 Digit Counting --- 水题

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

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

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

  3. Digit Counting UVA - 1225

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

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

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

  5. UVa 1225 Digit Counting

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

  6. UVa1225 Digit Counting

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

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

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

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

    题目描述:算法竞赛入门经典习题3-3 #include <stdio.h> #include <string.h> int main(int argc, char *argv[ ...

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

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

随机推荐

  1. puppet证书重申

  2. (转)iOS7界面设计规范(2) - UI基础 - iOS应用解析

    今天再来一发,然后结束掉周六的忙碌,去吃零食,还有冰啤酒:其实现在打嗝还有小龙虾味儿呢. 第二篇更多的是从技术的角度对iOS界面组成原理进行了简单的解析,篇幅很短,可稍作了解:更多关于iOS开发入门的 ...

  3. 使用AWS的EC2服务器,进行跳墙

    选Ubuntu的服务器 一开始先设置Root,命令:su root 在安装之前,先Update一下源:apt-get update update完就可以安装: 1.安装pi,命令:apt-get in ...

  4. JAVA单线程以及java多线程的实现方式

    1.java单线程的实现 public class SingletonThread { @SuppressWarnings("static-access") public stat ...

  5. C++ Primer 学习笔记_77_模板与泛型编程 --实例化

    模板与泛型编程 --实例化 引言: 模板是一个蓝图,它本身不是类或函数.编译器使用模板产生指定的类或函数的特定版本号.产生模板的特定类型实例的过程称为实例化. 模板在使用时将进行实例化,类模板在引用实 ...

  6. Linux环境下Eclipse + Tomcat + MySQL 配置J2EE开发环境的方法

    1. 版本号信息 (1)CentOS 6.4发行版64位,uname -a 显演示样例如以下: Linux localhost.localdomain 3.11.6 #1 SMP Sat Nov 2 ...

  7. DataBindings 与 INotifyPropertyChanged 实现自动刷新 WinForm 界面

    --首发于博客园, 转载请保留此链接  博客原文地址 业务逻辑与界面的分离对于维护与迁移是非常重要的,在界面上给某属性赋值,后台要检测到其已经发生变化 问题: 输入某物品 单价 Price, 数量Am ...

  8. artDialog Error: document.compatMode === "BackCompat 报错原因

    今天在使用artDialog的时候报错了提示artDialog Error: document.compatMode === "BackCompat 查了网上说 可以设置<!DOCTY ...

  9. word-wrap 和 word-break

    一.word-wrap 1.浏览器支持 所有主流浏览器都支持 word-wrap属性 2.定义和用法 word-wrap 属性允许长单词或 URL 地址换行到下一行. 语法 word-wrap: no ...

  10. SQL中常用的时间格式

    一些常用的时间格式 先讲一下一些基本的格式模式 格式模式      说明 d                   月中的某一天.一位数的日期没有前导零. dd                 月中的某 ...