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 |
AC哪!!#include<stdio.h> #include<math.h> int yueshu(int x,int y) { int a; if(x>y) { a=x; x=y; y=a; } while(1) { if(x%y==0) break; else { a=y; y=x%y; x=a; } } return y; } void main() { int a,b,c,d; int m,n,s; char e,f,g; while(scanf("%d%c%d%c%d%c%d",&a,&e,&b,&f,&c,&g,&d)!=EOF) { if(f=='+') { m=a*d+b*c; n=b*d; } else { m=a*d-b*c; n=b*d; } if(m>0) { s=yueshu(m,n); m=m/s; n=n/s; if(n==1) printf("%d\n",m); else printf("%d/%d\n",m,n); } if(m<0) { m=fabs(m); s=yueshu(m,n); m=m/s; n=n/s; if(n==1) printf("-%d\n",m); else printf("-%d/%d\n",m,n); } if(m==0) printf("0\n"); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator