Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
wa了三次....给出我的条件判断顺序吧...这是最终变形的几种情况判断,分母(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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator