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

能帮我看下为什么TLE么?

Posted by jimmysue at 2014-08-19 21:36:46 on Problem 1503
#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:
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