习题3-3 数数字 UVa1225
来源:互联网 发布:seo基础视频教程 编辑:程序博客网 时间:2024/06/10 01:44
1.题目描述:点击打开链接
2.解题思路:先构造这样的一个串,再一次查找该串中每个数字的个数即可。
3.代码:
#include<stdio.h>#include<string.h>#include<ctype.h>#define max 40000+10char s[max];int main(){int T;scanf("%d", &T);while (T--){int n;int first = 1;scanf("%d", &n);char*p = s;for (int i = 1; i <= n; i++){sprintf(p, "%d", i);if (i < 10) p++;//指针移动的位数要随着数字位数而调整else if (i < 100) p += 2;else if (i < 1000) p += 3;else if (i < 10000) p += 4;else p += 5;}int a[10];memset(a, 0, sizeof(a));int len = strlen(s);for (int i = 0; i < len; i++)switch (s[i]){case'0':a[0]++; break;case'1':a[1]++; break;case'2':a[2]++; break;case'3':a[3]++; break;case'4':a[4]++; break;case'5':a[5]++; break;case'6':a[6]++; break;case'7':a[7]++; break;case'8':a[8]++; break;case'9':a[9]++; break;}for (int i = 0; i < 10; i++){if (first) //注意第一个字符处不要有空格first = 0;elseprintf(" ");printf("%d", a[i]);}printf("\n");}return 0;}
0 0
- 习题3-3 数数字 UVa1225
- 习题3-3 数数字 UVa1225
- uva1225 数数字 字符串与数组03-习题3
- 算法竞赛入门经典(第2版)习题3-3 数数字 Digit Counting UVa1225
- 《算法竞赛入门经典2ndEdition 》习题3-3 数数字(Digit Counting, Uva1225)
- 习题3-3 数数字(Digit Counting , ACM/ICPC Danang 2007, UVa1225)
- 习题3-3Uva1225
- 习题3-3 Uva1225
- Uva1225之数数字
- UVA1225数数字
- 数数字 UVa1225
- 数数字 UVA1225
- 习题3-3 UVa1225 Digit Counting
- 习题3-3 数数字
- UVa1225 Digit Counting 数数字
- Uva1225-Digit Counting-数数字
- 算法竞赛入门经典(刘汝佳)习题3-3 UVa1225
- 习题3-3 数数字(Digit counting)
- python 远程线程注入代码
- 习惯养成
- 创建cocos2d-x+lua项目
- cf442C Artem and Array
- mysql replace的使用
- 习题3-3 数数字 UVa1225
- 中英携手的全球意义 李克强展示中国形象
- R900086516 PGH5-2X/080RR11VU2
- sdfsdiogfdhgkjd
- .NET获取windows域帐号
- 程序员在大学里究竟应该学习什么?
- setsockopt()
- AES 加密算法在 java AS JS中的实现_密码等的加密互解
- Swift初体验 (一)