Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

AC哪!!

Posted by xiao1074234390 at 2012-08-07 15:18:01 on Problem 3979
#include<stdio.h>
#include<math.h>
int yueshu(int x,int y)
{
	int a;
	if(x>y)
	{
		a=x;
		x=y;
		y=a;
	}
	while(1)
	{
		if(x%y==0)
			break;
		else
		{
			a=y;
			y=x%y;
			x=a;
		}
	}
	return y;
}
void main()
{
	int a,b,c,d;
	int m,n,s;
	char e,f,g;
	while(scanf("%d%c%d%c%d%c%d",&a,&e,&b,&f,&c,&g,&d)!=EOF)
	{
		if(f=='+')
		{
    		m=a*d+b*c;
			n=b*d;
		}
		else
		{
			m=a*d-b*c;
			n=b*d;
		}
		if(m>0)
		{
			s=yueshu(m,n);
			m=m/s;
			n=n/s;
			if(n==1)
			    printf("%d\n",m);
			else
				printf("%d/%d\n",m,n);
		}
		if(m<0)
		{
			m=fabs(m);
			s=yueshu(m,n);
			m=m/s;
			n=n/s;
			if(n==1)
			    printf("-%d\n",m);
			else
		    	printf("-%d/%d\n",m,n);
		}
		if(m==0)
			printf("0\n");
	}
}










Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator