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

BUG 在哪?

Posted by Euphorbia at 2010-12-01 19:44:04 on Problem 3979
#include<iostream>
#include<cmath>
using namespace std;
int gcd(int x, int y);
int main()
{
    int a1,a2,b1,b2;
	char c;
	while(scanf("%d/%d%c%d/%d",&a1,&a2,&c,&b1,&b2)!=EOF)
	{
                                                        int res,rex;
                                                        if('+'==c)
                                                        res=a1*b2+b1*a2;
                                                        else
                                                        res=a1*b2-b1*a2;
                                                        if(res==0){
                                                                   cout<<"0\n";
                                                                   continue;
                                                                   }
                                                        rex=a2*b2;
                                                        int temp;
                                                        temp=gcd(res,rex);
                                                        temp=temp>0?temp:-temp;
                                                        cout<<res/temp<<"/"<<rex/temp<<endl;                                  
     }
     return 0;
}
int gcd(int x, int y){ 
	if (!x ||!y) return x > y ? x : y; 
	for (int t; t = x % y; x = y, y = t); 
	return y; 
} 

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