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

各位大虾帮忙,为什么Run Time Error?

Posted by JosephJoe at 2007-12-14 15:35:00 on Problem 1504
#include<iostream>
using namespace std;
#define N 20
int reverse(int x);
int jiecheng(int x);
int main()
{
 int i,n,a[N],b[N],sum;
 cin>>n;
 for(i=1;i<=n;i++)
	{ scanf("%d %d",&a[i],&b[i]); 
   a[i]=reverse(a[i]);
   b[i]=reverse(b[i]);
   sum=a[i]+b[i];
   sum=reverse(sum);
   cout<<sum<<endl;
 }
 return 0;
}
int reverse(int x)
{
	int i,flag,sum,value[N],tempx,temp_value;
	tempx=x;
	temp_value=tempx-tempx/10*10;
	while(!temp_value)
	{	tempx=tempx/10;
		temp_value=tempx-tempx/10*10;
	}
	i=0;
	value[i]=temp_value;
	while(tempx)
	{  
		temp_value=tempx-tempx/10*10;
		 tempx=tempx/10;
		 value[i++]=temp_value;
	}
    flag=i-1;
	sum=0;
	for(i=0;i<=flag;i++)
	{sum+=value[i]*jiecheng(flag-i);
	}
	return sum;
}
int jiecheng(int x)
{
	int i=1,result=1;
	while(i<=x)
	{result*=10;
	i++;}
  return result;
}

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