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

代码写的非常的水,求大牛帮忙优化~~~

Posted by 2010201307 at 2012-02-18 19:48:25 on Problem 1503
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <map>
#include <vector>
#include <cmath>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
	int i,t=0,len;
	char a[1000];
	
	while(scanf("%s",a)!=EOF)
	{   
		char b[1000]={'0'};
		while(strcmp(a,"0")!=0)
		{			
			reverse(a,a+strlen(a));
		    len=strlen(a); 
			for(i=0;i<len;i++)
			{   if(i==(strlen(b)))	
				{
					b[i]='0';
				}
				t=(b[i]-'0')+(a[i]-'0')+t; 
				b[i]=t%10+'0';
				t=t/10;
				if(t&&i==(strlen(b)-1)) b[i+1]='0';	 
			}
			while(t)
			{
				t=(b[i]-'0')+t;
				b[i]=t%10+'0';
				t=t/10;
				if(t&&i==(strlen(b)-1))
				{
					b[i+1]='0';		
				}
				i++;	
			}
			scanf("%s",a);			
		}
		reverse(b,b+strlen(b));	 printf("%s\n",b);
	}
}

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