joj 1817: Triangle 三角形的判定

 1817: Triangle


Result TIME Limit MEMORY Limit Run Times AC Times JUDGE
5s 8192K 2409 685 Standard

2nd JOJ Cup Online VContest Problem

Given three integers a, b and c(|a|, |b|, |c|<10000), determine if they can compose a valid triangle. If so, further determine which kind of the triangle it is.

Input Specification

The input consists of several lines, each of which contains three integers a, b and c.

Output Specification

For each group of a b and c, first print "Case K:", a space, and then one of the following four lines:

is not a valid triangle.
is a sharp triangle.
is a right triangle.
is a blunt triangle.

corresponding to your determinant, where K is the number of the test cases starting from 1.

Sample Input

3 4 5
3 3 3
1 2 3
3 4 6

Sample Output

Case 1: is a right triangle.
Case 2: is a sharp triangle.
Case 3: is not a valid triangle.
Case 4: is a blunt triangle.

 

#include 
using namespace std;
int a,b,c,tmp;
int main()
{
	int count = 0;
	//while(scanf("%d%d%d",&a,&b,&c),a,b,c)
	while(cin>>a>>b>>c)
	{
		if(a < b)
		{
			tmp = a;
			a = b;
			b = tmp;
		}
		if(a < c)
		{
			tmp = a;
			a = c;
			c = tmp;
		}
		count ++ ;
		if(a >= (b + c))
		{
			printf("Case %d is not a valid triangle.\n",count);
			continue;
		}		
		if(a*a == b*b + c*c)
			printf("Case %d is a right triangle.\n",count);
		else if(a*a > b*b + c*c)
			printf("Case %d is a blunt triangle.\n",count);
		else if(a*a < b*b + c*c)
			printf("Case %d is a sharp triangle.\n",count);	
	}
	return 0;
}

 总是WA一点问题没有啊。。。

+01的正确代码

#include 
using namespace std;
int main(void){
	int a,b,c,r,count=0;
	while(cin>>a>>b>>c){
		if(a=b+c) //偶然的避开了 1  2  3时候 a*a > b* b + c*c
			cout<<"Case "<<++count<<": is not a valid triangle."<b*b+c*c)
			cout<<"Case "<<++count<<": is a blunt triangle."<
 

搞不明白

你可能感兴趣的:(ACM)