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

当我提交的那一刹那,我意识到一个bug。。然后我惊奇的发现竟然已经AC

Posted by rain_bow at 2009-09-14 14:51:00 on Problem 1503
程序;(详见错误处)
#include<iostream>
#include<string>
#include<math.h>
using namespace std;


int main()
{
	string s,re;
	cin>>re;
	int i,j,k,lre,ls;
	while(cin>>s&&s!="0")
	{
		lre=re.length();ls=s.length();
		int jin=0,tmp;
		if(lre>=ls)
		{
			for(i=lre-1,j=ls-1;j>=0;i--,j--)
			{
				
				tmp=re[i]+s[j]-'0'-'0'+jin;
				re[i]=tmp%10+'0';
				jin=tmp/10;
			}
			for(;i>=0;i--)
			{
				if(jin==0) break;
				tmp=re[i]+jin-'0';
				re[i]=tmp%10+'0';
				jin=tmp/10;
			}
			if(jin==1) re='1'+re;
		}
		else
		{
			for(i=lre-1,j=ls-1;i>=0;i--,j--)
			{
				tmp=re[i]+s[j]-'0'-'0'+jin;
				s[j]=tmp%10+'0';
				jin=tmp/10;
			}
			for(;j>=0;j--)
			{
				if(jin==0) break;
				tmp=s[j]+jin-'0';
				s[j]=tmp%10+'0';
				jin=tmp/10;				
			}
			if(jin==1) re='1'+s;	 
		        else  re=s;         //错误处
             //此处原来忘记加了。。也就是说poj的测试数据中不存在以后的数比原来的长度
              //长的大数了。。
		}
	}
	cout<<re<<endl;
	system("pause");
    return 0;
}

也就是说
对于
19999
4555555555
没有这种测试数据;

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