1 #include<stdio.h> 2 3 int cus(int x,int y) 4 { 5 if(y) 6 return cus(y,x%y); 7 else 8 return x; 9 } 10 int main() 11 { 12 int x1,x2,y1,y2; 13 char c; 14 while(~scanf("%d/%d%c%d/%d",&x1,&x2,&c,&y1,&y2)) 15 { 16 if(c=='+') 17 x1=(x1*y2)+(y1*x2); 18 else 19 x1=(x1*y2)-(y1*x2); 20 x2*=y2; 21 y1=x1>0?x1:-x1; 22 y2=cus(x2,y1); 23 x1/=y2,x2/=y2; 24 if(!x1) 25 puts("0"); 26 else if(x1%x2) 27 printf("%d/%d ",x1,x2); 28 else 29 printf("%d ",x1/x2); 30 } 31 }