Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class PytagoreanNumbers
- {
- static void Main()
- {
- short n = short.Parse(Console.ReadLine());
- int[] numbers = new int[n];
- for (int i = 0; i < n; i++)
- {
- numbers[i] = int.Parse(Console.ReadLine());
- }
- bool hasNumbers = false;
- List<string> products = new List<string>();
- Array.Sort(numbers);
- for (int i = 0; i < n; i++)
- {
- for (int j = i; j < n; j++)
- {
- for (int k = 0; k < n; k++)
- {
- if (!products.Contains(numbers[j].ToString() + numbers[i].ToString()))
- {
- if (numbers[i]*numbers[i] + numbers[j]*numbers[j] == numbers[k]*numbers[k])
- {
- PrintPow(numbers[i]);
- Console.Write(" + ");
- PrintPow(numbers[j]);
- Console.Write(" = ");
- PrintPow(numbers[k]);
- Console.WriteLine();
- hasNumbers = true;
- products.Add(numbers[i].ToString() + numbers[j].ToString());
- }
- }
- }
- }
- }
- if (!hasNumbers)
- {
- Console.WriteLine("No");
- }
- }
- static void PrintPow(int num)
- {
- Console.Write(num + "*" + num);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement