UVa 1225 / UVALive 3996 Digit Counting 数数字(字符统计)

Digit Counting

Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

Submit Status

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,把从1到n按顺序写在一起,统计数字0~9各个数出现的次数。
 1 #include<iostream>
 2 #include<string.h>
 3 #include<cstdio>
 4 using namespace std;
 5 int main()
 6 {
 7     int T,b,c,i,n,j,e,f;
 8     scanf("%d",&T);
 9     while(T--)
10     {
11         int k[10]={0};
12
13         scanf("%d",&n);
14         for(i=1;i<=n;i++)
15         {
16             f=i;
17             j=0;
18             int a[5]={0};
19             while(f!=0)
20             {
21                 a[j++]=f%10;
22                 f/=10;
23             }
24             for(int e=0;e<j;e++)
25                 k[a[e]]++;
26         }
27         for(i=0;i<10;i++)
28         {
29             if(i==0)
30                 printf("%d",k[i]);
31             else
32                 printf(" %d",k[i]);
33         }
34         printf("\n");
35     }
36     return 0;
37 }
时间: 2024-10-26 17:48:39

UVa 1225 / UVALive 3996 Digit Counting 数数字(字符统计)的相关文章

UVa 1225 Digit Counting --- 水题

UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现的次数,先将cnt初始化为0,接着让i从1枚举到n, 对每个i,处理以活的i的每一个位置上的数,并在相应的cnt下标上+1 最后输出cnt数组即可 /* UVa 1225 Digit Counting --- 水题 */ #include <cstdio> #include <cstring

UVA 1225 Digit Counting(统计数位出现的次数)

Digit Counting Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu SubmitStatus Description Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequence of consecutive integers starting

UVa 1583 Digit Generator(数)

For a positive integer N , the digit-sum of N is defined as the sum of N itself and its digits. When M is the digitsum of N , we call N a generator of M . For example, the digit-sum of 245 is 256 (= 245 + 2 + 4 + 5). Therefore, 245 is a generator of 

UVa1587.Digit Counting

题目连接: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 Tru

BZOJ2023: [Usaco2005 Nov]Ant Counting 数蚂蚁

2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 56  Solved: 16[Submit][Status] Description 有一天,贝茜无聊地坐在蚂蚁洞前看蚂蚁们进进出出地搬运食物.很快贝茜发现有些蚂蚁长得几乎一模一样,于是她认为那些蚂蚁是兄弟,也就是说它们是同一个家族里的成员.她也发现整个蚂蚁群里有时只有一只出来觅食,有时是几只,有时干脆整个蚁群一起出来.这样一来,

1630/2023: [Usaco2005 Nov]Ant Counting 数蚂蚁

2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 85  Solved: 40[Submit][Status][Discuss] Description 有一天,贝茜无聊地坐在蚂蚁洞前看蚂蚁们进进出出地搬运食物.很快贝茜发现有些蚂蚁长得几乎一模一样,于是她认为那些蚂蚁是兄弟,也就是说它们是同一个家族里的成员.她也发现整个蚂蚁群里有时只有一只出来觅食,有时是几只,有时干脆整个蚁群一

UVA1225 UVALive3996 Digit Counting

Regionals 2007 >> Asia - Danang 问题链接:UVA1225 UVALive3996 Digit Counting.入门练习题,用C语言编写程序. 这个问题是数字出现次数统计问题,按照套路处理就可以了. 本程序的套路包括,用运算符%从整数中取出数字,输出格式控制. AC的C语言程序如下: /* UVA1225 UVALive3996 Digit Counting */ #include <stdio.h> #include <memory.h>

UVA 12124 UVAlive 3971 Assemble(二分 + 贪心)

先从中找出性能最好的那个数, 在用钱比较少的去组合,能组出来就表明答案在mid的右边,反之在左边, #include<string.h> #include<map> #include<stdio.h> #include<iostream> #include<algorithm> using namespace std; map<string,int> vic;//以字符映射数字 int end,start; int num; int

java语言将任意一个十进制数数字转换为二进制形式,并输出转换后的结果

1 package com.llh.demo; 2 3 import java.util.Scanner; 4 5 /** 6 * 7 * @author llh 8 * 9 */ 10 public class Test { 11 /* 12 * 将任意一个十进制数数字转换为二进制形式,并输出转换后的结果(使用数组存储) 13 */ 14 public static void main(String[] args) { 15 Scanner sc = new Scanner(System.in