Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._Shopping_List
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> list = Console.ReadLine().Split("!").ToList();
  12.             string command = Console.ReadLine();
  13.  
  14.             while (command != "Go Shopping!")
  15.             {
  16.                 string[] split = command.Split();
  17.                 string item = split[1];
  18.                 if (command.Contains("Urgent"))
  19.                 {
  20.                     if (!list.Contains(item))
  21.                     {
  22.                         list.Insert(0, item);
  23.                     }
  24.                 }
  25.                 else if (command.Contains("Unnecessary"))
  26.                 {
  27.                    
  28.                     if (list.Contains(item))
  29.                     {
  30.                         list.Remove(item);
  31.                     }
  32.                 }
  33.                 else if (command.Contains("Correct"))
  34.                 {
  35.                     string newItem = split[2];
  36.                     if (list.Contains(item))
  37.                     {
  38.                         int index = list.IndexOf(item);
  39.                         list.Remove(item);
  40.                         list.Insert(index, newItem);
  41.                     }
  42.                 }
  43.                 else if (command.Contains("Rearrange"))
  44.                 {
  45.                     if (list.Contains(item))
  46.                     {
  47.                         list.Remove(item);
  48.                         list.Add(item);
  49.                     }
  50.                 }
  51.  
  52.                 command = Console.ReadLine();
  53.             }
  54.  
  55.             Console.WriteLine(String.Join(", ", list));
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement