《算法竞赛入门经典2ndEdition 》习题3-3 数数字(Digit Counting, Uva1225)
2015-12-01 21:27
435 查看
没找到什么更好的算法,这个也能过,就这样了。
不过话说uva居然不忽略行末空格,习惯了noip的忽略行末空格与文末回车,幸好uva给我的是PE,要不然估计死活都会改不出来。
不过话说uva居然不忽略行末空格,习惯了noip的忽略行末空格与文末回车,幸好uva给我的是PE,要不然估计死活都会改不出来。
#include <cstdio> #include <cstring> using namespace std; const int maxn = 10000; int num[maxn + 10][10]; int main() { int t, maxm = 0; scanf("%d", &t); while(t--) { int n; scanf("%d", &n); if(maxm < n) { for(int i = maxm+1; i <= n; i++) { int x = i; for(int j = 0; j <= 9; j++) num[i][j] = num[i-1][j]; while(x != 0) { num[i][x%10]++; x /= 10; } } maxm = n; } for(int i = 0; i < 9; i++) printf("%d ", num [i]); printf("%d\n", num [9]);//uva居然不忽略行末空格 } return 0; }
相关文章推荐
- 《算法竞赛入门经典》解题索引
- 1.10055 - Hashmat the brave warrior
- 2.10071 - Back to High School Physics
- 3.458 - The Decoder
- 4.694 - The Collatz Sequence
- 6.494 - Kindergarten Counting Game
- 7.490 - Rotating Sentences
- 8.414 - Machined Surfaces
- 9.488 - Triangle Wave
- A.457 - Linear Cellular Automata
- B.489 - Hangman Judge
- C.445 - Marvelous Mazes
- 1.10494 - If We Were a Child Again
- 2.424 - Integer Inquiry
- 3.10250 - The Other Two Trees
- 5.465 - Overflow
- 6.113 - Power of Cryptography
- 7.10161 - Ant on a Chessboard
- 8.621 - Secret Research
- UVA11367 加满油 解题报告