dhows

Untitled

May 31st, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace zad_399
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n;
  14.  
  15. do
  16. {
  17. Console.Write("Enter n: ");
  18. n = int.Parse(Console.ReadLine());
  19. } while (n > 31 || n <= 0);
  20. Console.WriteLine();
  21.  
  22. double[] A, B, C;
  23. Console.WriteLine("For station A:\n");
  24. A = enterValues(n);
  25.  
  26. Console.WriteLine("For station B:\n");
  27. B = enterValues(n);
  28.  
  29. Console.WriteLine("For station C:\n");
  30. C = enterValues(n);
  31.  
  32. Console.WriteLine();
  33.  
  34. //a
  35. Console.Write("Days it didnt rain in station A:\n{0} => ", daysItDidntRain(A).Count);
  36. string daysItDidntRainStr = "";
  37. foreach (var day in daysItDidntRain(A))
  38. {
  39. daysItDidntRainStr += day + ", ";
  40. }
  41. if (daysItDidntRainStr.Length <= 0)
  42. {
  43. daysItDidntRainStr = "none, ";
  44. }
  45. Console.WriteLine(daysItDidntRainStr.Substring(0, daysItDidntRainStr.Length - 2));
  46. daysItDidntRainStr = "";
  47. Console.WriteLine();
  48.  
  49. //b
  50. Console.Write("Days it didnt rain in station B:\n{0} => ", daysItDidntRain(B).Count);
  51. foreach (var day in daysItDidntRain(B))
  52. {
  53. daysItDidntRainStr += day + ", ";
  54. }
  55. if (daysItDidntRainStr.Length <= 0)
  56. {
  57. daysItDidntRainStr = "none, ";
  58. }
  59. Console.WriteLine(daysItDidntRainStr.Substring(0, daysItDidntRainStr.Length - 2));
  60. daysItDidntRainStr = "";
  61. Console.WriteLine();
  62.  
  63.  
  64. //c
  65. Console.Write("Days it didnt rain in station C:\n{0} => ", daysItDidntRain(C).Count);
  66. foreach (var day in daysItDidntRain(C))
  67. {
  68. daysItDidntRainStr += day + ", ";
  69. }
  70. if (daysItDidntRainStr.Length <= 0)
  71. {
  72. daysItDidntRainStr = "none, ";
  73. }
  74. Console.WriteLine(daysItDidntRainStr.Substring(0, daysItDidntRainStr.Length - 2));
  75. Console.WriteLine();
  76.  
  77. }
  78.  
  79. static List<int> daysItDidntRain(double[] days)
  80. {
  81. List<int> daysIndex = new List<int>();
  82. for (int i = 0; i < days.Length; i++)
  83. {
  84. if (days[i] == 0)
  85. {
  86. daysIndex.Add(i + 1);
  87. }
  88. }
  89. return daysIndex;
  90. }
  91.  
  92. static double[] enterValues(int n)
  93. {
  94. double[] days = new double[n];
  95. for (int i = 0; i < n; i++)
  96. {
  97. enterValue:
  98. Console.Write("Enter liters for m2 for day {0}: ", i + 1);
  99. days[i] = double.Parse(Console.ReadLine());
  100. if (days[i] < 0)
  101. {
  102. Console.WriteLine("You can't enter negative value!");
  103. goto enterValue;
  104. }
  105. }
  106.  
  107. return days;
  108. }
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment