Egypt#1265

Egypt (Editorial)

Let a, b, c be the sides of a triangle. A triangle is right-angled if one of the following conditions holds:

Algorithm implementation

Read the input data until the end of the file.

while(scanf("%d %d %d",&a,&b,&c))
{

If three zeros are encountered, terminate the program.

  if (a + b + c == 0) break;

Check whether the triangle is a right triangle. Print the result accordingly.

  if ((a * a + b * b == c * c) ||
      (a * a + c * c == b * b) ||
      (b * b + c * c == a * a))
    puts("right");
  else
    puts("wrong");
}

Java implementation

import java.util.*;

public class Main
{
  public static void main(String[] args)
  {
    Scanner con = new Scanner(System.in);
    while(con.hasNextInt())
    {
      int a = con.nextInt();
      int b = con.nextInt();
      int c = con.nextInt();

      if (a + b + c == 0) break;
      if ((a * a + b * b == c * c) ||
          (a * a + c * c == b * b) ||
          (b * b + c * c == a * a))
        System.out.println("right");
      else
        System.out.println("wrong");
    }
    con.close();
  }
}

Python implementation

Read the input data until the end of the file.

while True:
  a, b, c = map(int, input().split())

If three zeros are encountered, terminate the program.

  if a + b + c == 0: break

Check whether the triangle is a right triangle. Print the result accordingly.

  if (a * a + b * b == c * c) or (a * a + c * c == b * b) or 
     (b * b + c * c == a * a):
    print("right");
  else:
    print("wrong")