Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
- using System;
- using System.IO;
- using System.Linq;
- using System.Collections.Generic;
- namespace CSharp_Shell
- {
- public class P02_Shopping_List
- {
- public static void Main()
- {
- var list = Console.ReadLine()
- .Split(new []{"!", " "}, StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- while(true)
- {
- var input = Console.ReadLine();
- if(input == "Go Shopping!")
- {
- break;
- }
- var items = input.Split(" ");
- var command = items[0].ToLower();
- if(command == "urgent")
- {
- var item = items[1];
- var firstElement = list.First();
- if(firstElement == string.Empty)
- {
- list.Insert(0, item);
- }
- }
- if(command == "unnecessery")
- {
- var item = items[1];
- if(list.Contains(item))
- {
- list.Remove(item);
- }
- }
- if(command == "correct")
- {
- var oldItem = items[1];
- var newItem = items[2];
- if(list.Contains(oldItem))
- {
- var indexOld = list.IndexOf(oldItem);
- list.RemoveAt(indexOld);
- list.Insert(indexOld, newItem);
- }
- }
- if(command == "rearrange")
- {
- var item = items[1];
- if(list.Contains(item));
- {
- list.Remove(item);
- list.Add(item);
- }
- }
- }
- for(int i = 0; i<list.Count-1;i++)
- {
- Console.Write($"{list[i]}, ");
- }
- Console.Write(list.LastOrDefault());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement