Advertisement
Guest User

Untitled

a guest
May 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ConsoleApp1
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. init();
  10. }
  11. private static void init()
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14. // promenqsh bounda do koe chislo max da tursi
  15. int bound = 300;
  16. run(n,bound);
  17. }
  18. private static void run(int n, int bound)
  19. {
  20. int count = 0;
  21. List<List<int>> foundPairs = new List<List<int>>();
  22. while (count<n)
  23. {
  24. Random rnd = new Random();
  25. int a = rnd.Next(1, bound);
  26. int b = rnd.Next(1, bound);
  27. int c = rnd.Next(1, bound);
  28. int d = rnd.Next(1, bound);
  29. if (equation(a,b,c,d) && notFound(foundPairs, a, b, c, d))
  30. {
  31. List<int> pair = new List<int>();
  32. pair.Add(a);
  33. pair.Add(b);
  34. pair.Add(c);
  35. pair.Add(d);
  36. foundPairs.Add(pair);
  37. count++;
  38. Console.WriteLine($"{a}^2 + {b}^2 + {c}^2 = {d}^2");
  39. }
  40.  
  41. }
  42. }
  43. private static Boolean equation(int a, int b, int c, int d)
  44. {
  45. return a * a + b * b + c * c == d * d;
  46. }
  47. private static Boolean notFound(List<List<int>> pairs, int a, int b, int c,int d)
  48. {
  49. List<int> currentPair = new List<int>();
  50. currentPair.Add(a);
  51. currentPair.Add(b);
  52. currentPair.Add(c);
  53. currentPair.Add(d);
  54. currentPair.Sort();
  55. foreach ( List<int> pair in pairs)
  56. {
  57. pair.Sort();
  58. if ((currentPair[0].Equals(pair[0])) && (currentPair[1].Equals(pair[1])) &&
  59. (currentPair[2].Equals(pair[2])) && (currentPair[3].Equals(pair[3])))
  60. {
  61. return false;
  62. }
  63. }
  64. return true;
  65. }
  66.  
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement