nassss

Untitled

Nov 24th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace AlphaNumbers
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. //Alpha numbers are a very special kind of numbers because they follow a very special rule - the biggest non-negative difference between
  12. //all pairs must be larger than the last digit of the sum of all digits.Sounds hard?
  13.  
  14. //For example, 186 is an alpha number.
  15.  
  16. //The non-negative differences are 8 - 1 = 7, 8 - 6 = 2 and 6 - 1 = 5.
  17. //The sum of all digits is 1 + 8 + 6 = 15.
  18. //The biggest difference 7 is larger than the last digit of 15.
  19. //Input
  20. //Exactly 7 numbers, each on a new line.
  21.  
  22. //Output
  23. //Each alpha number on a new line, in the order given.
  24.  
  25. //Constraints
  26. //100 <= number <= 999
  27.  
  28. //Sample tests
  29. //Input
  30. //186
  31. //144
  32. //782
  33. //764
  34. //882
  35. //909
  36. //511
  37. //Output
  38. //186
  39. //909
  40. //Input
  41. //135
  42. //357
  43. //791
  44. //357
  45. //913
  46. //579
  47. //135
  48. //Output
  49. //791
  50. //913
  51. //579
  52.  
  53. List<int> output = new List<int>();
  54. for (int i = 0; i < 7; i++)
  55. {
  56. int input = int.Parse(Console.ReadLine());
  57. int firstDigit = input % 10;
  58. int secondDigit = (input / 10) % 10;
  59. int thirdDigit = (input / 100) % 10;
  60.  
  61. int largNum = Math.Max(firstDigit, Math.Max(secondDigit, thirdDigit));
  62. int smallerNum = Math.Min(firstDigit, Math.Min(secondDigit, thirdDigit));
  63. int middleNum = firstDigit + secondDigit + thirdDigit - largNum - smallerNum;
  64.  
  65. int biggestDiff = largNum - smallerNum;
  66. int digitsSumLastNum = (firstDigit + secondDigit + thirdDigit) % 10;
  67.  
  68. if (biggestDiff > digitsSumLastNum)
  69. {
  70. output.Add(input);
  71. }
  72. }
  73. foreach (var item in output)
  74. {
  75. Console.WriteLine(item);
  76. }
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment