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 |
彻底服了,怎么就WA呢?下面说的各种数据都测了,没问题!牛人帮忙看看,先谢了!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator