#include "stdio.h" #include "string.h" int main() { char s[10000],oper,a[10000],b[10000],c[10000],d[10000]; int i,j,k,len,ka,kb,kc,kd,numa,numb,numc,numd,up,down,up1,down1,com; while (gets(s)) { len=strlen(s); i=0;ka=kb=kc=kd=numa=numb=numc=numd=0; while(s[i]!='/') {a[ka++]=s[i++];numa=10*numa+a[ka-1]-48;} i++; while(s[i]!='+'&&s[i]!='-') {b[kb++]=s[i++];numb=10*numb+b[kb-1]-48;} oper=s[i]; i++; while(s[i]!='/') {c[kc++]=s[i++];numc=10*numc+c[kc-1]-48;} i++; while(s[i]!='/0') {d[kd++]=s[i++];numd=10*numd+d[kd-1]-48;} // printf("%d %d %d %d/n",numa,numb,numc,numd); if(oper=='+') { up=numa*numd+numb*numc;down=numb*numd; } else { up=numa*numd-numb*numc;down=numb*numd; } if(up<0) {printf("-");up=0-(numa*numd-numb*numc);} i=2;com=1;up1=up;down1=down; while(i<=up&&i<=down) { while(up%i==0&&down%i==0) {com*=i;up/=i;down/=i;} i++; } if(up1==0) printf("0/n"); else if(down==1) printf("%d/n",up); else printf("%d/%d/n",up,down); } return 0; }