Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 27761 | Accepted: 10775 |
Description
Input
Output
Sample Input
123456789012345678901234567890 123456789012345678901234567890 123456789012345678901234567890 0
Sample Output
370370367037037036703703703670
这道题目贡献了我10+次WA 就是因为没有考虑前导零的情况 我真心跪了!
#include <stdio.h> #include <string.h> #define N 105 int data[N][N]; int length = 0; int sum[N] = {0}; int StrlenOfThis(char *str) { char *s ; for(s = str; *s; s++) ; return (s-str); } void Convert(char str[]) { int i,j; for(j = 0,i = data[length][N-1]-1; i >=0; i--, j++) { data[length][j] = str[i]-'0'; } } void Sum() { int jinwei = 0,i,j,x; for(i = 0; i < length; i++) { for(j = 0; j < data[i][N-1] || jinwei > 0; j++) { x = sum[j] + data[i][j] + jinwei; jinwei = x / 10; sum[j] = x % 10; } jinwei = 0; } } void Show() { int i = N-1,j; while(sum[i]==0)i--; for(j = i; j >= 0; j--) printf("%d",sum[j]); printf("\n"); } int main() { char str[150]; int i; while(1) { scanf("%s",str); // 检测前导零的情况 for(i = 0; i < StrlenOfThis(str); i++) if(str[i] != '0')break; if(i == StrlenOfThis(str)) break; data[length][N-1] = StrlenOfThis(str); Convert(str); length++; memset(str,0,sizeof(str)); } if(length == 0) printf("0"); else{ Sum(); Show(); } return 1; }