UVA - 424 Integer Inquiry
2016-07-06 15:58
609 查看
题目大意:大整数相加
解题思路:读入 char 类型字符串,倒序储存于 int 类型的数组中,相加大于 10 进位,可能比原来大一位,倒序输出。
解题思路:读入 char 类型字符串,倒序储存于 int 类型的数组中,相加大于 10 进位,可能比原来大一位,倒序输出。
#include<iostream> #include<cstdio> #include<string.h> using namespace std; int str[1000][1000]; char s[1000]; int ans[1000]; int main() { int tot = 0; int max = 0; while(scanf("%s", s) != EOF) { if (strcmp(s,"0") == 0) break; int l = strlen(s); if (l > max) max = l; int j = 0; for (int i = l-1; i >= 0; i--) str[tot][j++] = s[i] - '0'; tot++; } for (int i = 0; i < max ; i++) for (int j = 0; j < tot; j++){ ans[i] += str[j][i]; if (ans[i] > 9) { ans[i+1]++; ans[i] -= 10; } } int i; if (ans[max] == 0) i = max - 1; else i = max; for (; i >= 0; i--) printf("%d", ans[i]); printf("\n"); 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
- 9.401 - Palindromes
- A.537 - Artificial Intelligence?