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:怎么会不过的?In Reply To:怎么会不过的? Posted by:qianwei at 2011-01-12 21:19:06 #include<stdio.h> int gcd(int x,int y){ int t; if(!x)return y; while(y){ t=x%y; x=y; y=t; } return x; } int main(){ int a,b,c,d,x,y,t; char o; while(5==scanf("%d / %d %c %d / %d",&a,&b,&o,&c,&d)){ y=b*d; switch(o){ case'+':x=a*d+b*c;break; case'-':x=a*d-b*c;break; } t=gcd(x,y); x/=t; y/=t; if(y<0){ y=-y; x=-x; } printf("%d",x); if(y!=1)printf("/%d",y); printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator