Algorithm
Problem link- https://www.spoj.com/problems/SCPC11D/
SCPC11D - Egypt
A long time ago, the Egyptians figured out that a triangle with sides of length 3, 4, and 5 had a right angle as its largest angle. You must determine if other triangles have a similar property.
Input
Input represents several test cases, followed by a line containing 0 0 0. Each test case has three positive integers, less than 30,000, denoting the lengths of the sides of a triangle.
Output
For each test case, a line containing "right" if the triangle is a right triangle, and a line containing "wrong" if the triangle is not a right triangle.
Example
Input:
6 8 10 25 52 60 5 12 13 0 0 0
Output: right wrong right
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <map>
#include <list>
using namespace std;
int main(){
while(true){
vector<int> x(3,0);
scanf("%d%d%d",&x[0],&x[1],&x[2]);
if(x[0]==0&&x[1]==0&&x[2]==0)break;
bool possible=true;
if(x[0]+x[1]<x[2])possible=false;
if(x[1]+x[2]<x[0])possible=false;
if(x[0]+x[2]<x[1])possible=false;
sort(x.begin(),x.end());
if(x[2]!=sqrt(x[1]*x[1]+x[0]*x[0]))
{
possible=false;
}
if(possible){
printf("right\n");
}
else{
printf("wrong\n");
}
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
25 52 60
5 12 13
0 0 0
Output
wrong
right
Demonstration
SPOJ Solution-Egypt-Solution in C, C++, Java, Python