TheBulgarianWolf

Course Planning- Softuni

Dec 19th, 2020
987
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Course_Planning
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("Enter your lessons and exercises here: ");
  11.             string line = Console.ReadLine();
  12.             string[] lineArr = line.Split(", ");
  13.             List<string> lineList = new List<string>(lineArr);
  14.             string command;
  15.             while ((command = Console.ReadLine()) != "course start")
  16.             {
  17.                 string[] commands = command.Split(":");
  18.                 string firstCommand = commands[0];
  19.                 string secondCommand = commands[1];
  20.                 if (firstCommand == "Add")
  21.                 {
  22.                     if (lineList.Contains(secondCommand) == false)
  23.                     {
  24.                         lineList.Add(secondCommand);
  25.                     }
  26.                 }
  27.                 else if (firstCommand == "Insert")
  28.                 {
  29.                     if (lineList.Contains(secondCommand) == false)
  30.                     {
  31.                         int index = int.Parse(commands[2]);
  32.                         lineList.Insert(index, secondCommand);
  33.                     }
  34.                 }
  35.                 else if (firstCommand == "Remove")
  36.                 {
  37.                     if (lineList.Contains(secondCommand) == true)
  38.                     {
  39.                         lineList.Remove(secondCommand);
  40.                     }
  41.                 }
  42.                 else if(firstCommand == "Swap")
  43.                 {
  44.                     string thirdCommand = commands[2];
  45.                     if (lineList.Contains(secondCommand) == true && lineList.Contains(thirdCommand) == true)
  46.                     {
  47.                         string firstElement = secondCommand;
  48.                         int firstIndex = lineList.IndexOf(secondCommand);
  49.                         string secondElement = thirdCommand;
  50.                         int secondIndex = lineList.IndexOf(thirdCommand);
  51.                         lineList[firstIndex] = secondElement;
  52.                         lineList[secondIndex] = firstElement;
  53.  
  54.                     }
  55.                 }
  56.                 else if(firstCommand == "Exercise")
  57.                 {
  58.                    
  59.                     if (lineList.Contains(secondCommand) == false)
  60.                     {
  61.                         lineList.Add(secondCommand);
  62.                         string commExerc = secondCommand + "-Exercise";
  63.                         lineList.Add(commExerc);
  64.                     }
  65.                     else
  66.                     {
  67.                         int index = lineList.IndexOf(secondCommand);
  68.                         string commExerc = secondCommand+ "-Exercise";
  69.                         lineList.Insert(index + 1, commExerc);
  70.                     }
  71.                 }
  72.                
  73.  
  74.             }
  75.  
  76.             for(int index = 0; index < lineList.Count; index++)
  77.             {
  78.                 Console.Write((index + 1) + lineList[index]);
  79.                 Console.WriteLine();
  80.             }
  81.         }
  82.     }
  83. }
  84.  
Add Comment
Please, Sign In to add comment