lolblach333

Untitled

Apr 15th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. namespace LocalMaximums
  5. {
  6. class Program
  7. {
  8. private const string
  9. InitialArray = "Массив: ",
  10. LocalMaximumsText = "Локальные максимумы выделены красным: ",
  11. Separator = " ";
  12. private const int
  13. Min = 0, Max = 20, ArrayLength = 30;
  14.  
  15. static void Main(string[] args)
  16. {
  17. int[] numbers = new int[ArrayLength];
  18. int[] maximums = new int[ArrayLength];
  19.  
  20. Random random = new Random();
  21.  
  22. for (int i = 0; i < ArrayLength; i++)
  23. {
  24. numbers[i] = random.Next(Min, Max);
  25. }
  26.  
  27. for (int i = 0; i < ArrayLength; i++)
  28. {
  29. switch (i)
  30. {
  31. case 0:
  32. {
  33. maximums[i] = numbers[i + 1] < numbers[i] ? 1 : 0;
  34. break;
  35. }
  36. case ArrayLength - 1:
  37. {
  38. maximums[i] = numbers[i - 1] < numbers[i] ? 1 : 0;
  39. break;
  40. }
  41. default:
  42. {
  43. maximums[i] = numbers[i - 1] < numbers[i] && numbers[i + 1] < numbers[i] ? 1 : 0;
  44. break;
  45. }
  46. }
  47. }
  48.  
  49. Console.WriteLine(InitialArray);
  50. Console.WriteLine(string.Join(Separator, numbers));
  51.  
  52. Console.WriteLine(LocalMaximumsText);
  53.  
  54. for (int i = 0; i < ArrayLength; i++)
  55. {
  56. Console.ForegroundColor = maximums[i] == 0 ? ConsoleColor.Gray : ConsoleColor.Red;
  57. Console.Write(numbers[i] + Separator);
  58. }
  59.  
  60. Console.ReadKey();
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment