`

zoj 3488 conic section

阅读更多

题目见zoj 3488

很简单的题目,却没能一次搞定,因为没看清楚题目中输入数据都是实数。

该题目考察浮点数的比较(因为浮点数在计算机中存储是近似存储,所以不能直接将两个浮点数直接用大于或小于符号相比较)

 

 

/* zoj 3488 conic section */
#include <stdio.h>
#include <math.h>

#define SMALLNUM 1e-8

int main(void)
{
  double a,b,c,d,e,f;
  int n;
  
  scanf("%d", &n);
  while(n-- > 0)
    {
      scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f);
      if(fabs(a-c) < SMALLNUM)
	printf("circle\n");
      else if(a * c < -SMALLNUM)
	printf("hyperbola\n");
      else if(a * c > SMALLNUM)
	printf("ellipse\n");
      else 
 	printf("parabola\n");
    }
  return 0;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics