课后题 3-3 水题

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

Status

Description
Download as PDF
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

给你一个数字   从1 开始到这个数字  意见 一共出现了 多少个  1 -  9   统计一下       n<10000

 1 //  题 虽然很水  但是    这种  消去最后一个 空格的方式值得学习.
 2 #include<stdio.h>
 3 #include<string.h>
 4 void cmp();
 5 int a[10000][10];
 6 int main()
 7 {
 8     int i,j,m,n,q,b,c,t;
 9     scanf("%d",&t);
10     cmp();
11     while(t--)
12     {
13         scanf("%d",&n);
14         for(i=0;i<9;i++)
15             printf("%d ",a[n][i]);
16         printf("%d\n",a[n][9]);
17     }
18 }
19 void cmp()
20 {
21     memset(a,0,sizeof(a));
22     for(int i=1;i<10000;i++)
23     {
24         for(int j=1;j<=i;j++)
25         {
26             if(j<10)
27                 a[i][j]++;
28             else
29                 if(j<100)
30             {
31                 a[i][j/10]++;
32                 a[i][j%10]++;
33             }
34             else
35                 if(j<1000)
36             {
37                 a[i][j/100]++;
38                 a[i][j%10]++;
39                 a[i][(j-(j/100)*100-j%10)/10]++;
40             }
41             else
42             {
43                 a[i][j/1000]++;
44                 a[i][j/100-(j/1000)*10]++;
45                 a[i][(j%100-j%10)/10]++;
46                 a[i][j%10]++;
47             }
48         }
49     }
50 }
时间: 2024-10-08 03:22:32

课后题 3-3 水题的相关文章

poj水题-3062 超级水题的深层理解——代码简化

题目很简单,要求输入什么样输出什么样.以回车结束 这就是我用的C代码 #include <stdio.h> int main (){char p;for(;gets(&p);)puts(&p);return 0;} 使用了代码简化方案,我简化到了75B.有大神简化到31B,真想看看他们的源代码.我估计他们比我个能够了解语言规则. 这里不得不说一本叫<短码之美>的书.介绍了这道题.但我试过了,没用.可能系统升级了吧,必须要求C99. ,还听说不用#include也行,

2016 acm香港网络赛 F题. Crazy Driver(水题)

原题网址:https://open.kattis.com/problems/driver Crazy Driver In the Linear City, there are N gates arranged in a straight line. The gates are labelled from 1 to N. Between adjacent gates, there is a bidirectional road. Each road takes one hour to travel

HDU6292 赛题分析【水题】

赛题分析 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 1506 Accepted Submission(s): 637 Problem Description 著名出题人小Q每次比赛后都会写一份<赛题分析>,包含比赛概况.每题的参考算法以及一些统计数值. 对于一道题来说,小Q会统计最短的验题人代码长度(Shortest judge

HDU1302_Snail【模拟题】【水题】

The Snail Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1488    Accepted Submission(s): 1092 Problem Description A snail is at the bottom of a 6-foot well and wants to climb to the top. The s

刷了500道水题是什么体验?

并没有什么卵用. 我马上大二了,大一两学期目测切了1000道水题了,毫无意义. 至今不理解kmp和后缀数组,只会模板.数论和博弈论是什么?能吃吗?只会打表.图论至今不会tarjan,话说dlx是什么?插头dp,这是什么?数据结构还好,经常做高中生的题,可持久化可持久化线段树也能花一下午时间写出来,然而并不会考. 平时做题只刷水题,遇到难题的时候,随手搜题解,看了看,哇,这居然能这么搞!然后抄一遍别人代码,交上去ac. cf一年几乎没缺过,花了大一上半年时间才滚上div1.然而至今紫号一堆,黄名一

刷水题(二)

今天,我又去刷水题了.水题好多呀!这些题分为N个难度级别,做出第i个难度级别的任意一题都需要a[i]分钟,并获得b[i]点积分.我最多可以刷T分钟水题,问我最多能获得多少积分? [输入] 第一行两个正整数N和T,接下来的N行每行两个正整数数a[i]和b[i]. [输出] 一个数,表示我最多可以获得的积分. [样例输入] 4 50 1 10 3 40 9 130 27 400 [样例输出] 720 题解: 直接上代码(没错,就是这么简单) 1 #include<iostream> 2 using

POJ3994 HDU3354 UVALive4736 Probability One【水题】

Probability One Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1944 Accepted: 1335 Description Number guessing is a popular game between elementary-school kids. Teachers encourage pupils to play the game as it enhances their arithmetic sk

2015南阳CCPC L - Huatuo&#39;s Medicine 水题

L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous doctor. He use identical bottles to carry the medicine. There are different types of medicine. Huatuo put medicines into the bottles and chain these b

sdut 2841 Bit Problem (水题)

题目 贴这个题是因为看题解有更简单的方法, 我做的时候是直接算的, 也很简单. 贴一下题解吧: 如果一个整数不等于 0,那么该整数的二进制表示中至少有一位是 1. 这个题结果可以直接输出 x - (x&(x-1)); 因为x-1 之后二进制下,就是最右边的1变成了0, 最右边的1的 右边所有的0变成了1, 不影响最左边. 我的代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4