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

所有的数据都对了,但是一直是run time error!!

Posted by gfedcba at 2011-02-12 22:13:03 on Problem 3979
#include "stdio.h"

//辗转相除法求最大公约数

int gcd(int m, int n)
{
	if (n == 0)
	{
		return m;
	}
	if (m < n)
	{
		int tmp = m;
		m = n;
		n = tmp;
	}
	gcd(n,m%n);
}


void fun(int a, int b, int c, int d, int o)
{
	a = a*d;
	c = c*b;
	//准备计算出结果的分子n跟分母m
	int n;
	o ? n = a+c : n = a-c;
	int m = b*d;

	//求出公约数
	int mnGcd = gcd(m, n > 0 ? n : -n);

	//分子分母约分
	n = n/mnGcd;
	m = m/mnGcd;

	//判断是否是整数
	if(n%m == 0)
	{
		printf("%d\n",n/m);
	}
	else
	{
		printf("%d/%d\n",n,m);
	}

}
int main()
{
	char str[8];
	while(scanf("%s",&str)!=EOF)
	{
		fun(str[0]-'0',str[2]-'0',str[4]-'0',str[6]-'0',str[3]=='+');
	}

}

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