| ||||||||||
| 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 | |||||||||
怎么会不过的?#include <stdio.h>
#include <string.h>
int main()
{
int a,b,c,d,adbc,bd;
char o,xx;
while(scanf("%d%c%d%c%d%c%d",&a,&xx,&b,&o,&c,&xx,&d)!=EOF)
{
if(o=='-')
{
if(a/b<c/d)printf("-");
adbc=a*d-b*c;
}else adbc=a*d+b*c;
bd=b*d;
for(int temp=2;temp<=81;temp++) if(adbc%temp==0 && bd%temp==0){adbc/=temp;bd/=temp;temp=2;}
if(adbc<0)adbc*=-1;
if(bd<0)bd*=-1;
if(adbc==0) printf("0\n");
else if(bd==1) printf("%d\n",adbc);
else printf("%d/%d\n",adbc,bd);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator