Advertisement
Lexvolk

Untitled

Aug 22nd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace IMJunior
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             List<GoalsStorage> goalsLists = new List<GoalsStorage>();
  11.             goalsLists.Add(new GoalsStorage("Личный"));
  12.             goalsLists.Add(new GoalsStorage("Рабочий"));
  13.             goalsLists.Add(new GoalsStorage("Семейный"));
  14.  
  15.             while (true)
  16.             {
  17.                 Console.Clear();
  18.                 //поиск длинны самого длинного списка на данный момент
  19.                 int max = GetLongestArraySize(goalsLists);
  20.  
  21.                 PrintHeader(goalsLists);
  22.                 for (int i = 0; i < max; i++)
  23.                 {
  24.                     foreach (var goalsList in goalsLists)
  25.                         goalsList.WriteGoal(i);
  26.  
  27.                     Console.WriteLine();
  28.                 }
  29.  
  30.                 Console.WriteLine("Куда вы хотите добавить цель?");
  31.                 string listName = Console.ReadLine(); //то что введёт пользователь переведённое в нижний регистр
  32.                 Console.WriteLine("Что это за цель?");
  33.                 string goalText = Console.ReadLine();
  34.  
  35.                 //Здесь нельзя использовать Array.Resize
  36.                 AddGoal(listName, goalText, goalsLists);
  37.             }
  38.         }
  39.  
  40.         private static void PrintHeader(List<GoalsStorage> storages)
  41.         {
  42.             foreach (var storage in storages)
  43.                 Console.Write(storage.Name + " | ");
  44.             Console.WriteLine();
  45.         }
  46.  
  47.         private static int GetLongestArraySize(List<GoalsStorage> storages)
  48.         {
  49.             int max = int.MinValue;
  50.             foreach (var storage in storages)
  51.                 if (storage.Length > max)
  52.                     max = storage.Length;
  53.             return max;
  54.         }
  55.  
  56.         private static void AddGoal(string storageName, string goalText, List<GoalsStorage> storages)
  57.         {
  58.             foreach (var storage in storages)
  59.                 if(storageName.ToLower() == storage.Name.ToLower())
  60.                 {
  61.                     storage.Add(goalText);
  62.                     break;
  63.                 }
  64.         }
  65.     }
  66.  
  67.     class GoalsStorage
  68.     {
  69.         public string Name { get; }
  70.         public int Length => _goals.Length;
  71.  
  72.         private Goal[] _goals = new Goal[0];
  73.  
  74.         public GoalsStorage(string name)
  75.         {
  76.             Name = name;
  77.         }
  78.  
  79.         public void Add(string goalText)
  80.         {
  81.             Goal[] goalsArrayNew = new Goal[_goals.Length + 1];
  82.             for (int j = 0; j < _goals.Length; j++)
  83.                 goalsArrayNew[j] = _goals[j];
  84.  
  85.             goalsArrayNew[goalsArrayNew.Length - 1] = new Goal(goalText);
  86.             _goals = goalsArrayNew;
  87.         }
  88.  
  89.         public void WriteGoal(int index)
  90.         {
  91.             if (_goals.Length > index)
  92.                 Console.Write(_goals[index].Text + " | ");
  93.             else
  94.                 Console.Write("Empty | ");
  95.         }
  96.     }
  97.  
  98.     class Goal
  99.     {
  100.         public string Text;
  101.  
  102.         public Goal(string text)
  103.         {
  104.             Text = text;
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement