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 |
Re:超时怎么回事啊 啊?????????????????In Reply To:超时怎么回事啊 啊????????????????? Posted by:IOVE at 2011-04-13 15:02:16 #include<iostream> #include<string> using namespace std ; const int N = 6 ; int A[ N ] ; int gb( int a, int b ) { int x ; for( x = a ; x <= a*b ; x += a ) { if( x % b == 0 ) break ; } return x ; } int main() { string a ; int i, j, m, n, k ; while( cin >> a ) { j = 0 ; i = 0 ; for( i = 0 ; i < a.size() ;i++ ) { if( i == 0 || i == 2 || i == 4 || i == 6 ) { A[ i ] = a[ i ] - '0' ; } } if( A[ 2 ] != A[ 6 ] ) { k = gb( A[ 2 ], A[ 6 ] ) ; m = k / A[ 2 ] ; n = k / A[ 6 ] ; A[ 0 ] = m * A[ 0 ] ; A[ 4 ] = n * A[ 4 ] ; if( a[ 3 ] == '+' ) { if( k >= A[ 0 ] + A[ 4 ] ) { if( k % ( A[ 0 ] + A[ 4 ] ) == 0 && ( k != A[ 0 ] + A[ 4 ] ) ) cout << 1 << "/" << k / ( A[ 0 ] + A[ 4 ] ) ; else if( k % ( A[ 0 ] + A[ 4 ]) != 0 ) cout << A[ 0 ] + A[ 4 ] << "/" << k << endl ; else cout << 1 << endl ; } else { if( ( A[ 0 ] + A[ 4 ] ) % k == 0 ) cout << ( A[ 0 ] + A[ 4 ] ) / k << endl ; else cout << A[ 0 ] + A[ 4 ] << "/" << k << endl ; } } else if( a[ 3 ] == '-' ) { if( A[ 0 ] - A[ 4 ] != 0 ) { if( abs( A[ 0 ] - A[ 4 ] ) <= k ) { if( k % abs( A[ 0 ] - A[ 4 ] ) == 0 && k != A[ 0 ] - A[ 4 ] ) cout << ( A[ 0 ] > A[ 4 ] ? 1 : -1 ) << "/" << k / abs( A[ 0 ] - A[ 4 ] ) << endl ; else if( k % abs( A[ 0 ] - A[ 4 ] ) != 0 ) cout << A[ 0 ] - A[ 4 ] << "/" << k << endl ; else if( k == A[ 0 ] - A[ 4 ] ) cout << 1 << endl ; } else { if( abs( A[ 0 ] - A[ 4 ] ) % k == 0 ) cout << ( A[ 0 ] - A[ 4 ] ) / k << endl ; else cout << A[ 0 ] - A[ 4 ] << "/" << k << endl ; } } else if( A[ 0 ] == A[ 4 ] ) { cout << 0 << endl ; } } } else if( A[ 2 ] == A[ 6 ] ) { if( a[ 3 ] == '+' ) { if( A[ 0 ] + A[ 4 ] <= A[ 2 ] ) { if( A[ 2 ] % ( A[ 0 ] + A[ 4 ] ) == 0 && A[ 2 ] != ( A[ 0 ] + A[ 4 ] ) ) cout << 1 << "/" << A[ 2 ] / ( A[ 0 ] + A[ 4 ] ) << endl ; else if( A[ 2 ] % ( A[ 0 ] + A[ 4 ] ) != 0 ) cout << A[ 0 ] + A[ 4 ] << "/" << A[ 2 ] << endl ; else cout << 1 << endl ; } else { if( ( A[ 0 ] + A[ 4 ] ) % A[ 2 ] == 0 ) cout << ( A[ 0 ] + A[ 4 ] ) / A[ 2 ] << endl ; else cout << A[ 0 ] + A[ 4 ] << "/" << A[ 2 ] << endl ; } } else if( a[ 3 ] == '-' ) { if( A[ 0 ] != A[ 4 ] ) { if( abs(A[ 0 ] - A[ 4 ]) <= A[ 2 ] ) { if( A[ 2 ] % abs( A[ 0 ] - A[ 4 ] ) == 0 && A[ 2 ] != ( A[ 0 ] - A[ 4 ] ) ) cout << ( A[ 0 ] > A[ 4 ] ? 1 : -1) << A[ 2 ] / abs( A[ 0 ] - A[ 4 ] ) << endl ; else if( A[ 2 ] % abs( A[ 0 ] - A[ 4 ] ) != 0 ) cout << A[ 0 ] - A[ 4 ] << "/" << A[ 2 ] << endl; else if( A[ 2 ] == A[ 0 ] - A[ 4 ] ) cout << 1 << endl ; } else if( abs( A[ 0 ] - A[ 4 ] ) >A[ 2 ] ) { if( abs( A[ 0 ] - A[ 4 ] ) % A[ 2 ] == 0 ) cout << ( A[ 0 ] - A[ 4 ] ) / A[ 2 ] << endl ; else cout << A[ 0 ] - A[ 4 ] << "/" << A[ 2 ] << endl ; } } else cout << 0 << 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