1 #include<stdio.h>
2 #include<stdlib.h>
3 int main()
4 {
5 char operand;
6 int a,b,c,d,e,f,flag,end;
7 while(scanf("%d/%d%c%d/%d",&a,&b,&operand,&c,&d)!=EOF)
8 {
9 if(operand=='+') //e为分子,f为分母
10 e=a*d+b*c;
11 else
12 e=a*d-b*c;
13 f=b*d;
14 while(1)
15 {
16 flag=1;
17 end=abs(e)<abs(f)?abs(e):abs(f);//分子分母化简过程 ,abs求整数的绝对值
18 for(a=2;a<=end;a++)
19 if(e%a==0&&f%a==0)
20 {
21 flag=0;//可以化简
22 e/=a;
23 f/=a;
24 break;
25 }
26 if(flag)
27 break;
28 }
29 if(e==f)
30 printf("%d\n",1);
31 else if(e==0||f==1)
32 printf("%d\n",e);
33 else
34 printf("%d/%d\n",e,f);
35 }
36 return 0;
37 }