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

为什么答案总是错的!哪位高手帮帮忙啊!(附代码,)代码很简单,帮忙看看。

Posted by huangsiqin at 2012-07-04 11:01:57 on Problem 3979
#include <stdio.h>
#include <math.h>
int main()
{
	int a1,b1,a2,b2,a3,b3,i;
	char c;
	while (scanf("%d/%d%c%d/%d",&b1,&a1,&c,&b2,&a2)!=EOF)
	{
		a3=a1*a2;
		if (c=='+')
		{
			b3=a2*b1+a1*b2;
		}
		if (c=='-')
		{
			b3=a2*b1-a1*b2;
		}
		for(i=2;i<=sqrt(a3)&&i<=sqrt(fabs(b3));)
		{
			if (a3%i==0&&b3%i==0)
			{
				a3=a3/i;
				b3=b3/i;
				i=2;
			}
			else
				i++;
		}
		if (b3==0)
		{
			printf("0\n");
		}
		else if (b3%a3==0)
		{
			printf("%d\n",b3/a3);
		}
		else
		{
			printf("%d/%d\n",b3,a3);
		}
	}
	return 0; 
}


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