Advertisement
Guest User

Untitled

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