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

wa了三次....给出我的条件判断顺序吧...

Posted by yeozach at 2017-04-11 20:21:27 on Problem 3979
这是最终变形的几种情况判断,分母(down )为0时就只打分子就行了。要注意只判断一次分母为1是不够的,除了gcd以后还要判断一次。另外gcd传统写法可能算出负数(因为传进来的有负数),要注意一下。


	if ( up == down ){
	
		up = 1;
		down = 0;//a flag
		return ;
	
	}
	else if ( up * ( -1 ) == down ){
	
		up = -1;
		down = 0;
		return ;
	
	}
	else if ( up == 0 ){
	
		down = 0;
		return ;
	
	}
	else if ( down == 1 ){
	
		down = 0;
		return ;
	
	}

	int t;
	t = gcd ( up, down );

	up /= t;
	down /= t;

	if ( down == 1 ){
	
		down = 0;
		return ;
	
	}

	return ;

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