A题
来源:互联网 发布:轩辕传奇账号交易淘宝 编辑:程序博客网 时间:2024/06/06 01:21
Trung is bored with his mathematicshomeworks. He takes a piece of chalk and starts writing a sequence ofconsecutive integers starting with 1 to N (1 < N < 10000). After that, hecounts the number of times each digit (0 to 9) appears in the sequence. Forexample, with N = 13, the sequence is: 12345678910111213 In this sequence, 0appears once, 1 appears 6 times, 2 appears 2 times, 3 appears 3 times, and eachdigit from 4 to 9 appears once. After playing for a while, Trung gets boredagain. He now wants to write a program to do this for him. Your task is to helphim with writing this program. Input The input file consists of several datasets. The first line of the input file contains the number of data sets whichis a positive integer and is not bigger than 20. The following lines describethe data sets. For each test case, there is one single line containing thenumber N. Output For each test case, write sequentially in one line the numberof 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
链接:https://cn.vjudge.net/contest/160964#problem/A
题意:输入一个N, 统计1~N中,0~9出现的次数;
解题:
因为N最大只有10000,组数<=20,可以直接循环统计0~9 的个数。
代码如下:
#include<stdio.h>int main(){int t,n;scanf("%d",&t);while(t--){int a[10]={0},i;scanf("%d",&n);for(i=1;i<=n;i++){int x=i;while(x){a[x%10]++;x/=10;}}for(i=0;i<9;i++)printf("%d ",a[i]);printf("%d\n",a[9]);}}
- A题
- A题
- 搜索比赛A题
- A题 数塔
- 第四届省赛A题
- a++的一道题
- 每日一题A
- 每日一题A
- 每日一题A
- A题感受
- CCPC 2015 A题
- 16初出茅庐A题
- A题常用数据结构
- SCU2016-04 A题
- A题 海岛争霸
- 湖南省赛A题
- 湘潭CCPC A题
- A. Table----思维题
- mac Android Studio内存配置与使用情况的展示
- 笔记5-JAVA的初学浅识(Java 对象和类 简单例子)
- Android报错IllegalArgumentException: Service Intent must be explicit
- Xcode开发c++程序时,openssl/aes.h: No such file or directory(或者是file not found)怎么解决
- uva 567 risk floyd
- A题
- spring集成mybatis后,打印SQL语句
- AngularJS入门之Angular内置指令
- openGL— 中点Bresenham画圆
- Xamarin.ios 下拉刷新效果
- Android--打开相机直接获取所拍摄的图片
- 虚函数 析构函数
- Keep learning, be curious!目标就在前方,努力就对了。
- 官方推荐react-navigation的使用