Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace zad_399
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n;
- do
- {
- Console.Write("Enter n: ");
- n = int.Parse(Console.ReadLine());
- } while (n > 31 || n <= 0);
- Console.WriteLine();
- double[] A, B, C;
- Console.WriteLine("For station A:\n");
- A = enterValues(n);
- Console.WriteLine("For station B:\n");
- B = enterValues(n);
- Console.WriteLine("For station C:\n");
- C = enterValues(n);
- Console.WriteLine();
- //a
- Console.Write("Days it didnt rain in station A:\n{0} => ", daysItDidntRain(A).Count);
- string daysItDidntRainStr = "";
- foreach (var day in daysItDidntRain(A))
- {
- daysItDidntRainStr += day + ", ";
- }
- if (daysItDidntRainStr.Length <= 0)
- {
- daysItDidntRainStr = "none, ";
- }
- Console.WriteLine(daysItDidntRainStr.Substring(0, daysItDidntRainStr.Length - 2));
- daysItDidntRainStr = "";
- Console.WriteLine();
- //b
- Console.Write("Days it didnt rain in station B:\n{0} => ", daysItDidntRain(B).Count);
- foreach (var day in daysItDidntRain(B))
- {
- daysItDidntRainStr += day + ", ";
- }
- if (daysItDidntRainStr.Length <= 0)
- {
- daysItDidntRainStr = "none, ";
- }
- Console.WriteLine(daysItDidntRainStr.Substring(0, daysItDidntRainStr.Length - 2));
- daysItDidntRainStr = "";
- Console.WriteLine();
- //c
- Console.Write("Days it didnt rain in station C:\n{0} => ", daysItDidntRain(C).Count);
- foreach (var day in daysItDidntRain(C))
- {
- daysItDidntRainStr += day + ", ";
- }
- if (daysItDidntRainStr.Length <= 0)
- {
- daysItDidntRainStr = "none, ";
- }
- Console.WriteLine(daysItDidntRainStr.Substring(0, daysItDidntRainStr.Length - 2));
- Console.WriteLine();
- }
- static List<int> daysItDidntRain(double[] days)
- {
- List<int> daysIndex = new List<int>();
- for (int i = 0; i < days.Length; i++)
- {
- if (days[i] == 0)
- {
- daysIndex.Add(i + 1);
- }
- }
- return daysIndex;
- }
- static double[] enterValues(int n)
- {
- double[] days = new double[n];
- for (int i = 0; i < n; i++)
- {
- enterValue:
- Console.Write("Enter liters for m2 for day {0}: ", i + 1);
- days[i] = double.Parse(Console.ReadLine());
- if (days[i] < 0)
- {
- Console.WriteLine("You can't enter negative value!");
- goto enterValue;
- }
- }
- return days;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment