| ||||||||||
| 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:BUG 在哪?In Reply To:BUG 在哪? Posted by:Euphorbia at 2010-12-01 19:44:04 > #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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator