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

彻底服了,怎么就WA呢?下面说的各种数据都测了,没问题!牛人帮忙看看,先谢了!

Posted by ganghelloworld at 2010-05-20 20:07:52 on Problem 2845
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define digit(c) (c - '0')
int main()
{
    int n, i, j, k, alen, blen, len, c, tag, count;
    char a[84], b[84], sum[84];
    scanf("%d", &n);
    for(k = 1; k <= n; k++)
    {
        for(i = 0; i < 84; i++)
        {
            a[i] = b[i] = sum[i] = '\0';
        }
        if(scanf("%s %s", a, b) != 2) return 0;
        alen = strlen(a);
        blen = strlen(b);
        c = 0;
        len = 0;
        for(i = alen-1, j = blen-1; i >= 0 && j >= 0; i--, j--)
        {
            sum[len++] = (digit(a[i]) + digit(b[j]) + c) % 2;
            c = (digit(a[i]) + digit(b[j]) + c) / 2;
        }
        if(i >= 0 && j < 0)
        {
            while(i >= 0)
            {
                sum[len++] = digit(a[i]) + c;
                c = 0;
                i--;
            }
        }
        else if(i < 0 && j >= 0)
        {
            while(j >= 0)
            {
                sum[len++] = digit(b[j]) + c;
                c = 0;
                j--;
            }
        }
        sum[len++] = c;
        tag = 1;
        printf("%d ", k);
        count = 0;
        for(i = len-1; i >= 0; i--)
        {
            if(tag)
            {
                if(sum[i] == 0)
                    continue;
                else
                    tag = 0;
            }
            printf("%d", sum[i]);
            count++;
        }
        if(!count) printf("0");
        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