Advertisement
Ares4077

Untitled

Jan 17th, 2020
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.96 KB | None | 0 0
  1. public class Tasks
  2.     {
  3.         public Tasks()
  4.         { }
  5.         private List<string> months = new List<string>();
  6.         private List<List<int>> days = new List<List<int>>();
  7.         private List<List<List<string>>> quantities = new List<List<List<string>>>();
  8.         public List<int> this[string month]
  9.         {
  10.             get => this.days[FindIndex(month)];
  11.         }
  12.         public List<string> this[string month, int day]
  13.         {
  14.             get => this.quantities[FindIndex(month)][FindIndex(month, day)];
  15.         }
  16.         public string this[string month, int day, int index_of_quantity]
  17.         {
  18.             get => this.quantities[FindIndex(month)][FindIndex(month, day)][index_of_quantity];
  19.         }
  20.         public int FindIndex(string month)
  21.         {
  22.             for (int i = 0; i < this.months.Count; i++)
  23.             {
  24.                 if (month == this.months[i])
  25.                 { return i; }
  26.             }
  27.             return -1;
  28.         }
  29.         public int FindIndex(string month, int day)
  30.         {
  31.             if (is_contain(month))
  32.             {
  33.                 for (int i = 0; i < this.days[FindIndex(month)].Count; i++)
  34.                 {
  35.                     if (day == days[FindIndex(month)][i])
  36.                     {
  37.                         return i;
  38.                     }
  39.                 }
  40.                 return -1;
  41.             }
  42.             return -1;
  43.         }
  44.         public bool is_contain(string month)
  45.         {
  46.             for (int i = 0; i < this.months.Count; i++)
  47.             {
  48.                 if (month == months[i])
  49.                 { return true; }
  50.             }
  51.             return false;
  52.         }
  53.         public bool is_contain(string month, int day)
  54.         {
  55.             if (is_contain(month))
  56.             {
  57.                 for (int i = 0; i < this.days[FindIndex(month)].Count; i++)
  58.                 {
  59.                     if (day == this.days[FindIndex(month)][i])
  60.                     { return true; }
  61.                 }
  62.                 return false;
  63.             }
  64.             return false;
  65.         }
  66.         public void Add_Task()
  67.         {
  68.             Console.WriteLine("Введите название месяца: ");
  69.             string month = Console.ReadLine();
  70.             if (FindIndex(month) > -1)
  71.             {
  72.                 Console.WriteLine("Введите число: ");
  73.                 int day = Console.Read();
  74.                 if (FindIndex(month, day) > -1)
  75.                 {
  76.                     Console.WriteLine("Введите количество добавляемых дел на число: ");
  77.                     int count = Console.Read();
  78.                     for (int i = 0; i < count; i++)
  79.                     {
  80.                         string Quantity = Console.ReadLine();
  81.                         this[month, day].Add(Quantity);
  82.                     }
  83.                 }
  84.                 else
  85.                 {
  86.                     this[month].Add(day);
  87.                     this.quantities[FindIndex(month)].Add(new List<string>());
  88.                     Console.WriteLine("Введите количество добавляемых дел на число: ");
  89.                     int count = Console.Read();
  90.                     for (int i = 0; i < count; i++)
  91.                     {
  92.                         string Quantity = Console.ReadLine();
  93.                         this[month, day].Add(Quantity);
  94.                     }
  95.                 }
  96.             }
  97.             else
  98.             {
  99.                 this.months.Add(month);
  100.  
  101.                 Console.WriteLine("Введите число: ");
  102.                 int day = Console.Read();
  103.  
  104.                 this[month].Add(day);
  105.                 this.quantities[FindIndex(month)].Add(new List<string>());
  106.  
  107.                 Console.WriteLine("Введите количество добавляемых дел на число: ");
  108.                 int count = Console.Read();
  109.  
  110.                 for (int i = 0; i < count; i++)
  111.                 {
  112.                     string Quantity = Console.ReadLine();
  113.                     this[month, day].Add(Quantity);
  114.                 }
  115.             }
  116.         }
  117.         public void Get_Tasks(string month, int day)
  118.         {
  119.             if (is_contain(month, day))
  120.             {
  121.                 Console.WriteLine($"Дела на {day} число {month}я: ");
  122.                 for (int i = 0; i < this[month, day].Count; i++)
  123.                 {
  124.                     Console.WriteLine((i).ToString() + this[month, day][i] + ".");
  125.                 }
  126.             }
  127.             else
  128.             {
  129.                 Console.WriteLine("Ошибка! Дела на заданное число не обнаружены! Желаете добавить новые дела?");
  130.                 string answer = Console.ReadLine();
  131.                 if (answer == "Да" || answer == "да" || answer == "ДА")
  132.                 {
  133.                     Add_Task();
  134.                 }
  135.             }
  136.         }
  137.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement