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 925695531 at 2011-02-13 16:36:11 on Problem 3979
In Reply To:为什么会错哦,怎么会。。。 Posted by:925695531 at 2011-02-13 15:13:39
> #include<iostream>
> using namespace std;
> 
> char a[8] , b;
> int x , y , z , w;
> int up , down ,i ;
> 
> int main()
> {
> 	while( cin >> a )
> 	{
> 		x = a[0] - '0';
> 		y = a[2] - '0';
> 		z = a[4] - '0';
> 		w = a[6] - '0';
> 		if( a[3] == '-' )
> 		{
> 			up = x * w - z * y ;
> 			down = y * w;
> 		}
> 		else
> 		{
> 			up = x * w + z * y ;
> 			down = y * w ;
> 		}
> 		
> 		
> 		if( up < 0 )
> 		{
> 			up = - up;
> 			for ( i = 1 ;i <= up ;i ++ )
> 				if ( up % i == 0 && down % i == 0)
> 				{
> 					up  /= i;
> 					down  /= i;
> 					i = 1;
> 				}
> 			if( down == 1 ) {
> 				cout<<"-"<<up<<endl;
> 				continue;
> 		    }
> 			cout <<"-"<<up<<"/"<<down<<endl;
> 		}
> 		else{
> 			if( up == 0 ) cout<<0<<endl;
> 			else{
> 				for ( i = 1 ;i <= up ;i ++ )
> 				if ( up % i == 0 && down % i == 0)
> 				{
> 					up /= i;
> 					down /= i;
> 					i = 1;
> 				}
> 			    if( down == 1 ) {
> 				    cout<<up<<endl;
> 				    continue;
> 		        }			
> 				cout<<up<<"/"<<down<<endl;
> 			}
> 		}
> 	}
> 	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