化简分数
#include<cstdio>
#include<algorithm>
using namespace std;
struct Fraction{
int down;
int up;
};
int gcd(int a,int b)
{
if(b==0) return a;
else{
return gcd(b,a%b);
}
}
Fraction reduction(Fraction r)
{
if(r.down<0)
{
r.up=-r.up;
r.down=-r.down;
}
if(r.up==0)
{
r.down=1;
}
else{
int g=gcd(abs(r.down),abs(r.up));
r.down/=g;
r.up/=g;
}
return r;
}
void showFraction(Fraction r)
{
r=reduction(r);
if(r.down == 1) printf("%lld",r.up);
else if(abs(r.up)>r.down)
{
printf("%d %d/%d",r.up/r.down,abs(r.up)%r.down,r.down);
}
else{
printf("%d/%d",r.up,r.down);
}
}
int main()
{
Fraction r;
scanf("%d/%d",&r.up,&r.down);
showFraction(r);
}