| ||||||||||
| 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 | |||||||||
这。。一直wrong answer怎么破、。。#include<iostream>
using namespace std;
int max(int x,int y)
{
return (x>y?x:y);
}
int ab(int x)
{
if(x<0) return -x;
else return x;
}
int yue(int x,int y)
{
int t;
if(x < y) {t=x;x=y;y=t;}
if(y==0) return x;
int k = x % y;
yue(y,k);
}
int bei(int x,int y)
{
int i;
for(i=max(x,y);;i++)
if(i%x==0 && i%y==0) return i;
}
int main()
{
int a,b,c,d,e;
char m,n;
while(cin >> a >> n >> b >> m >> c >> n >> d)
{
int l=bei(b,d);
a*=(l/b);
c*=(l/d);
if(m=='+') e=a+c;
else e=a-c;
if(e==0) {cout << 0 << endl;continue;}
int p=yue(ab(e),l);
e/=p;
l/=p;
if(l==1) cout << e << endl;
else cout << e << "/" << l << 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