Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace hz
  5. {
  6. class Program
  7. {
  8.  
  9.  
  10. static double[] ReadIntArray()
  11. {
  12. double[] numsArray;
  13. bool flag = false;
  14. do
  15. {
  16. flag = true;
  17. string buff = Console.ReadLine();
  18. numsArray = new double[buff.Split(' ').Length];
  19.  
  20. if (buff.Split(' ').Length > 120 || buff.Split(' ').Length < 1)
  21. {
  22. Console.WriteLine("Введите числа ещё раз, позязя!");
  23. flag = false;
  24. continue;
  25. }
  26.  
  27. int i = 0;
  28. foreach (var item in buff.Split(' '))
  29. {
  30. if (!double.TryParse(item, out numsArray[i])
  31. || Math.Abs(numsArray[i]) > 1025)
  32. {
  33. Console.WriteLine("Введите числа ещё раз, позязя!");
  34. flag = false;
  35. continue;
  36. }
  37. i++;
  38. }
  39.  
  40. } while (!flag);
  41.  
  42.  
  43. return numsArray;
  44. }
  45. static void ShowGistogramm(double[] numsArray, double min, double max, char symbol)
  46. {
  47. //Console.WriteLine(numsArray.Length);
  48.  
  49. for (int i = 10; i > 0; i--)
  50. {
  51. //Выводим максимум и минимум.
  52. if (i == 10)
  53. Console.Write($"{max:f2}\t|\t");
  54. else if (i == 1)
  55. Console.Write($"{min:f2}\t|\t");
  56. else
  57. Console.Write("\t|\t");
  58.  
  59. //Для копипасты 1 2 3 4 5 6 7 8 9
  60. foreach (var item in numsArray)
  61. {
  62. Console.Write(item >= i ? symbol : ' ');
  63. }
  64. Console.Write("\r\n");
  65. }
  66. }
  67.  
  68. static char ReadChar()
  69. {
  70. char symbol;
  71. do
  72. {
  73. Console.WriteLine("Соизвольте ввести символ.");
  74. } while (!char.TryParse(Console.ReadLine(), out symbol));
  75. Console.WriteLine();
  76. return symbol;
  77. }
  78. static void Main(string[] args)
  79. {
  80. //1 2 3 4 5 6 7 8 9 10
  81. Console.WriteLine("Введите числа через пробел");
  82. double[] nums = ReadIntArray();
  83. double[] numsD = new double[nums.Length];
  84.  
  85. double maxN = nums.Max();
  86. double minN = nums.Min();
  87. for (int i = 0; i < nums.Length; i++)
  88. {
  89. numsD[i] = Math.Round(1.0 * (nums[i] - minN) / (maxN - minN) * 10.0);
  90. }
  91.  
  92. ShowGistogramm(numsD, minN, maxN, ReadChar());
  93.  
  94. Console.WriteLine("До свидания");
  95. Console.ReadKey();
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement