约分最简分式(15)

#include<stdio.h>
int main()
{
	int n,m;
	int a,b,r;
	char e;
	while(scanf("%d",&n)!=EOF)
	{
		scanf("%c%d",&e,&m);
		if(n<1||m<1||e!='/') continue;
		a=(m>n)?m:n;
		b=(m<n)?m:n;
		r=a%b;
		while(r)
		{
			a=b;
			b=r;
			r=a%b;
		}
		printf("%d%c%d\n",n/b,e,m/b);
	}
	return 0;
}

posted on 2015-01-24 12:13  赛亚人  阅读(749)  评论(0编辑  收藏  举报