Advertisement
radidim

Shopping list (C# Shell App Paste)

Apr 11th, 2020
1,188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Collections.Generic;
  6.  
  7. namespace CSharp_Shell
  8. {
  9.  
  10.     public class P02_Shopping_List
  11.     {
  12.         public static void Main()
  13.         {
  14.             var list = Console.ReadLine()
  15.             .Split(new []{"!", " "}, StringSplitOptions.RemoveEmptyEntries)
  16.             .ToList();
  17.            
  18.             while(true)
  19.             {
  20.                 var input = Console.ReadLine();
  21.                
  22.                 if(input == "Go Shopping!")
  23.                 {
  24.                     break;
  25.                 }
  26.                
  27.                 var items = input.Split(" ");
  28.                
  29.                 var command = items[0].ToLower();
  30.                 if(command == "urgent")
  31.                 {
  32.                     var item = items[1];
  33.                     var firstElement = list.First();
  34.                    
  35.                     if(firstElement == string.Empty)
  36.                     {
  37.                         list.Insert(0, item);
  38.                     }
  39.                    
  40.                    
  41.                 }
  42.                
  43.                 if(command == "unnecessery")
  44.                 {
  45.                     var item = items[1];
  46.                     if(list.Contains(item))
  47.                     {
  48.                         list.Remove(item);
  49.                     }
  50.                 }
  51.                
  52.                 if(command == "correct")
  53.                 {
  54.                     var oldItem = items[1];
  55.                     var newItem = items[2];
  56.                     if(list.Contains(oldItem))
  57.                     {
  58.                         var indexOld = list.IndexOf(oldItem);
  59.                         list.RemoveAt(indexOld);
  60.                         list.Insert(indexOld, newItem);
  61.                     }
  62.                 }
  63.                
  64.                 if(command == "rearrange")
  65.                 {
  66.                     var item = items[1];
  67.                    
  68.                     if(list.Contains(item));
  69.                     {
  70.                         list.Remove(item);
  71.                         list.Add(item);
  72.                     }
  73.                 }
  74.                
  75.                
  76.             }
  77.            
  78.             for(int i = 0; i<list.Count-1;i++)
  79.             {
  80.                 Console.Write($"{list[i]}, ");
  81.             }
  82.             Console.Write(list.LastOrDefault());
  83.            
  84.            
  85.            
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement