| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
练了一年后的代码果然比一开始写的优雅很多。#include <cstdio>
#include <cstring>
using namespace std;
#define MAXN 105
char s[MAXN];
int d[MAXN];
int main() {
while (scanf("%s", s)) {
if (strcmp(s, "0") == 0) break;
int n = strlen(s);
for (int i = 0; i < n; ++i) {
d[i] += s[n - 1 - i] - '0';
}
}
for (int i = 0; i + 1 < MAXN; ++i) {
if (d[i] >= 10) {
d[i + 1] += d[i] / 10;
d[i] %= 10;
}
}
int k = MAXN;
while (d[--k] == 0);
while (k >= 0) printf("%d", d[k--]);
printf("\n");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator