import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()) {
String str=sc.next();
char a[]=str.toCharArray();
int fm=(a[2]-'0')*(a[6]-'0');
int fz=a[3]=='+'?((a[0]-'0')*(a[6]-'0')+(a[4]-'0')*(a[2]-'0')):((a[0]-'0')*(a[6]-'0')-(a[4]-'0')*(a[2]-'0'));
int x,y;
if(fz<0) {
x=-fz;
y=-fm;
}
else {
x=fz;
y=fm;
}
int t;
if(fz>fm) {
t=fz;fz=fm;fm=t;
}
while(fz!=0) {
int r=fm%fz;
fm=fz;
fz=r;
}
if((x/fm)%(y/fm)==0) {
System.out.println((x/fm)/(y/fm));
}
else {
System.out.println(x/fm+"/"+y/fm);
}
}
sc.close();
}
}
分数加减法
最新推荐文章于 2021-07-15 14:22:13 发布