ZOJ-1241ストランドの定理

1366 ワード

1241:a,b直角辺,c斜辺は両側が他方を求めることが知られている.
簡単な問題.浮動小数点数は大きさと判定を等しくしないため、辺は整型を採用し、結果は浮動小数点型を採用する.

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int main()
{
	int a;
	int b;
	int c;
	double res;
	int n=1;

	while(1)
	{	
		cin>>a;
		cin>>b;
		cin>>c;

		if(a==0&&b==0&&c==0)
			break;
		else
			printf("Triangle #%d
",n++); if(a==-1) { if(b>0&&c>0&&c>b) { res=sqrt((double)(c*c-b*b)); printf("a = %.3f
",res); } else printf("Impossible.
"); } else if(b==-1) { if(a>0&&c>0&&c>a) { res=sqrt((double)(c*c-a*a)); printf("b = %.3f
",res); } else printf("Impossible.
"); } else if(c==-1) { if(a>0&&b>0) { res=sqrt((double)(a*a+b*b)); printf("c = %.3f
",res); } else printf("Impossible.
"); } printf("
"); } }