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<cstdio> #include<string.h> using namespace std; char s[10]; int gcd(int a,int b){ return b == 0 ? a : gcd(b,a%b); } int main(){ while(~scanf("%s",s)){ int x1 = s[0]-'0',y1 = s[2]-'0',x2 = s[4]-'0',y2 = s[6]-'0'; char way = s[3]; int all = y1 * y2 / gcd(y1,y2); //printf("%d\n",all); int now_x; if(way == '-'){ now_x = x1 * all / y1 - x2 * all / y2; }else{ now_x = x1 * all / y1 + x2 * all / y2; } if(now_x % all == 0){ // 0 1 2 ... printf("%d\n",now_x / all); } else { if(now_x < 0) { printf("-"); now_x = -now_x; } int t = gcd(now_x,all); printf("%d/%d\n",now_x / t,all / t); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator