UVa1587.Digit Counting
| 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的更多相关文章
- UVa 1225 Digit Counting --- 水题
UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...
- UVA1225 - Digit Counting(紫书习题3.3)
Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequen ...
- Digit Counting UVA - 1225
Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequ ...
- 数数字 (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& ...
- 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 ...
- 数数字 (Digit Counting,ACM/ICPC Dannang 2007 ,UVa1225)
题目描述:算法竞赛入门经典习题3-3 #include <stdio.h> #include <string.h> int main(int argc, char *argv[ ...
- UVa 1225 - Digit Counting - ACM/ICPC Danang 2007 解题报告 - C语言
1.题目大意 把前n$(n\le 10000)$个整数顺次写在一起:12345678910111213……计算0~9各出现了多少次. 2.思路 第一想法是打表,然而觉得稍微有点暴力.不过暂时没有想到更 ...
随机推荐
- centerOS安装chkrootkit
Chkrootkit是一个在本地系统检查rootkit痕迹的工具,它是检查系统二进制文件是否被rootkit病毒修改的一个shell脚本. (1)centerOS安装chkrootkit 安装gcc编 ...
- JAVA泛型编程笔记
1介绍 Java泛型编程是JDK1.5版本后引入的.泛型让编程人员能够使用类型抽象,通常用于集合里面. 下面是一个不用泛型例子: List myIntList=new LinkedList(); // ...
- 5分钟精通git教程
git是一个版本控制工具,就要先弄清楚什么是版本 版本: 对外发布的版本如v1.0.0,v1.1.0 叫version 内部代码的版本叫commit,如:修改了一个错别字 顾名思义一个version就 ...
- JSF和Struts的区别概述
JSF和Struts的区别概述,都采用taglib来处理表示层:在jsp页面中,二者都是采用一套标记库来处理页面的表示和model层的交互. 据说JSF的主要负责人就是struts的主要作者,所以二者 ...
- 基于drools创建自己的关系操作符
我们知道drools提供了12种关系操作符 但是有些时候这12种操作符依然不能满足我们的业务需求,我们可以扩展自己的操作符,下面是为某一航空公司做项目时扩展了操作符,在这分享下 首先,我们要实现的逻辑 ...
- Git实现从本地加入项目到远程仓库
Git是如今最流行的版本号控制系统之中的一个了,今天也试试了.成功了上传了远程仓库,接下来看看我是怎么做的. 1.首先,要有git的账号.点击查看怎么注冊? 2.注冊成功之后.登陆GitHub.然后, ...
- oracle数据库常用查询一
oracle数据库常用查询一 sqlplus / as sysdba; 或sqlplus sys/密码 as sysdba;两者都是以sys登录.conn scott/tiger@orcl; conn ...
- 一张图看懂dex
最近在看dex文件格式,看的是飞虫大大的android软件安全与逆向分析一书,写的条理很清晰.相对于elf文件来说,dex文件格式简单了很多,但是提到某个字段,仍然难以想象其所处位置.所以一直想用思维 ...
- ibatis之##与$$的 使用
/** 主要讲一下ibatis中$$的使用: 是为了传递参数; 参数一定在Action层用''包裹起来: */ List <SysRole> userList= systemService ...
- 用JS来计算百钱买百鸡
怎样用一百块买一百只鸡?已知公鸡5块一只,母鸡3块一只,小鸡一块钱3只: 需要用到for循环嵌套,并且通过优化代码,可以加快运行效率. <!DOCTYPE html> <html l ...