首页 > ACM题库 > HDU-杭电 > HDU 4142-Triangle-计算几何-[解题报告]HOJ
2015
04-16

HDU 4142-Triangle-计算几何-[解题报告]HOJ

Triangle

问题描述 :

A triangle is one of the basic shapes of geometry: a polygon with three corners or vertices and three sides or edges which are line segments.
Triangles can be classified according to the relative lengths of their sides:
・ In an equilateral triangle all sides have the same length. An equilateral triangle is also a regular polygon with all angles measuring 60°.
・ In an isosceles triangle, two sides are equal in length. An isosceles triangle also has two angles of the same measure; namely, the angles opposite to the two sides of the same length; this fact is the content of the Isosceles triangle theorem.
・ In a scalene triangle, all sides are unequal. The three angles are also all different in measure. Some (but not all) scalene triangles are also right triangles.
Crank

输入:

The first line of input contains an integer (1 <= T <= 100), the number of test cases. T test data sets follow, each data set consists of 3 integers A, B and C, where (1 <= A,B,C <= 1,000,000) the triangle side lengths.

输出:

The first line of input contains an integer (1 <= T <= 100), the number of test cases. T test data sets follow, each data set consists of 3 integers A, B and C, where (1 <= A,B,C <= 1,000,000) the triangle side lengths.

样例输入:

2
3 3 4
6 4 2

样例输出:

Case #1: isosceles
Case #2: invalid!

// 判断三角形是等边三角形,等腰三角形,普通三角形,和不能组成三角形
#include<iostream>
#include<string>
#include<string.h>
using namespace std;

int main()
{	
	int n, p=1;
	scanf("%d", &n);
	while(n--)
	{
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		if(a > b)
			swap(a, b);
		if(b > c)
			swap(b, c);
		if(a > b)
			swap(a, b);
		printf("Case #%d: ", p++);
		if(a+b <= c)
			printf("invalid!\n");
		else if(a==b && b==c)
			printf("equilateral\n");
		else if(a==b || b==c)
			printf("isosceles\n");
		else
			printf("scalene\n");

	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

参考:http://blog.csdn.net/asure__cpp/article/details/12401963


  1. bottes vernies blanches

    I appreciate the efforts you men and women place in to share blogs on such sort of matters, it was certainly useful. Keep Posting!

  2. 第二个方法挺不错。NewHead代表新的头节点,通过递归找到最后一个节点之后,就把这个节点赋给NewHead,然后一直返回返回,中途这个值是没有变化的,一边返回一边把相应的指针方向颠倒,最后结束时返回新的头节点到主函数。