Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

练了一年后的代码果然比一开始写的优雅很多。

Posted by alex4814 at 2013-12-07 21:58:55 on Problem 1503
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator