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 |
能帮我看下为什么TLE么?#include <stdio.h> #include <stdlib.h> #include <string.h> char sum[102]; char num[102]; int main() { //char buffer[102] = {0}; memset(sum,'0',102); int sum_start; int num_len; char carry; int i; int j; while(1) { fgets(num,102,stdin); num_len = strlen(num); if(strcmp(num,"0")==0) break; j = 100; i = num_len-2; carry =0; while(i>=0){ sum[j] += num[i]-'0'+carry; if(sum[j]> '9'){ sum[j] -= 10; carry = 1; }else carry = 0; --j; --i; } while(carry){ sum[j]+=carry; if(sum[j]> '9'){ sum[j] -= 10; carry = 1; }else carry = 0; --j; } } sum_start = 0; while(sum[sum_start] == '0') sum_start++; sum[101] = 0; printf("%s\n",sum+sum_start); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator