| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
原来是这样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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator