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

Re:Why is wrong answer?

Posted by rainyw at 2008-05-01 01:26:28 on Problem 1503
In Reply To:Why is wrong answer? Posted by:chj8081 at 2008-02-02 17:41:54
>    #include <iostream>
> #include <string>
> //#include <FSTREAM>
> using namespace std;
> 
> string rever(string a){
> 	int l,i;
> 	string s;
> 	l=a.length();
> 	for(i=l-1;i>=0;i--){
> 		s+=a[i];
> 	}
> 	return s;
> 
> }
> void main()
> {
> 	string ad,re_ad;
> 	int sum[20000]={0},i,tmp,j,adl;
> //	ifstream in("input.txt");
> 	while(1){
> 		cin>>ad;
> 		if(ad[0]=='0')
> 			break;
> 		re_ad=rever(ad);
> 		adl=ad.length();
> 
> 		for(i=0;i<adl;i++){
> 			tmp=sum[i]+re_ad[i]-'0';
> 			sum[i]=tmp%10;
> 			sum[i+1]+=tmp/10;
> 		}
> 
> 	}
> 
> 	for(i=19999;i>=0;i--){
> 		if(sum[i]!=0){
> 			for(j=i;j>=0;j--)
> 				cout<<sum[j];
> 			break;
> 		}
> 	}
> 	
> 	cout<<endl;
> 
> }

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