博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Digit Counting UVA - 1225
阅读量:6179 次
发布时间:2019-06-21

本文共 1717 字,大约阅读时间需要 5 分钟。

Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequence of consecutive integers starting with 1 toN(1 < N < 10000) . After that, he counts the number of times each digit (0 to 9) appears in the sequence. For example, withN = 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.

 

 

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 .

 

 

For each test case, write sequentially in one line the number of digit 0, 1,...9 separated by a space.

 

 

 

2 3 13

 

 

 

0 1 1 1 0 0 0 0 0 0 1 6 2 2 1 1 1 1 1 1 这个题目刚做的时候觉得非常简单,一会就敲完啦,但交上去之后显示时间超时,问题出现在输入的数字上,在逻辑上面,我的程序已经出现了漏洞。不多说了,看代码吧;
#include
#include
#define maxn 10int main(){ int N; int a[maxn]; scanf("%d",&N); while(N--){ int n,i,j; memset(a,0,sizeof(a)); scanf("%d",&n); for(i=1;i<=n;i++){ //for(j=i;j>0;j/=10) // a[j%10]++; j=i; while(j) { a[j%10]++; j/=10; } } printf("%d",a[0]); for(i=1;i<10;i++) printf(" %d",a[i]); printf("\n"); } return 0;}

  

转载于:https://www.cnblogs.com/yongzi/p/7363051.html

你可能感兴趣的文章
Gartner:财务应用迁移到云 速度超出预期
查看>>
阿里云向物流业渗透 货运司机受益
查看>>
灾难恢复的人为因素:经理们应该做的10件事情
查看>>
中国教育行业可能到了最不平凡的10年:要么创新,要么死亡
查看>>
学习Docker的User Namespace
查看>>
Symantec Backup Exec 2012 Agent for Linux 卸载
查看>>
用EJB进行事务管理
查看>>
Linux Shell脚本系列之一
查看>>
数据可视化,个人经验总结(Echarts相关)
查看>>
Mysql MAC installation
查看>>
一款基于Vue和Go的桌面端管理star项目应用
查看>>
使用shell创建一个简单的菜单bash select用法
查看>>
Nuxt之默认模版和默认布局
查看>>
Vue模板、JS、CSS分离实现
查看>>
Hexo -- 快速、简洁且高效的博客框架 入门
查看>>
JVM
查看>>
高并发面试总结
查看>>
Pycharm--Python文件开头自动添加utf-8编码
查看>>
Leetcode PHP题解--D60 824. Goat Latin
查看>>
2019年一线大厂春招:Spring面试题和答案合集(上篇)
查看>>