Advertisement
gospod1978

MidExam/Group2/Wizard Poker

Nov 12th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Text;
  6.  
  7. namespace fundamental14
  8. {
  9.     class MainClass
  10.     {
  11.         public static void Main()
  12.         {
  13.             List<string> card = Console.ReadLine().Split(":").ToList();
  14.             List<string> cardN = new List<string>();
  15.            
  16.             string input = string.Empty;
  17.             while((input = Console.ReadLine())!= "Ready")
  18.             {
  19.                 string[] array = input.Split().ToArray();
  20.                 string command = array[0];
  21.                 string cardName = array[1];
  22.                 int indexRem = 0;
  23.                
  24.                 if (command == "Add")
  25.                 {
  26.                     if(!card.Contains(cardName))
  27.                     {
  28.                         Console.WriteLine("Card not found.");
  29.                     }
  30.                     else
  31.                     {
  32.                         indexRem = card.IndexOf(cardName);
  33.                         cardN.Add(cardName);
  34.                         card.RemoveAt(indexRem);
  35.                     }
  36.                 }
  37.                 else if (command == "Insert")
  38.                 {
  39.                     int index = int.Parse(array[2]);
  40.                     if (index >= 0 && index < cardN.Count && card.Contains(cardName))
  41.                     {
  42.                         indexRem = card.IndexOf(cardName);
  43.                         card.RemoveAt(indexRem);
  44.                         cardN.Insert(index, cardName);
  45.                        
  46.                     }
  47.                     else
  48.                     {
  49.                         Console.WriteLine("Error!");
  50.                     }
  51.                 }
  52.                 else if (command == "Remove")
  53.                 {
  54.                     if (cardN.Contains(cardName))
  55.                    {
  56.                     indexRem = cardN.IndexOf(cardName);
  57.                     cardN.RemoveAt(indexRem);
  58.                     }
  59.                     else
  60.                     {
  61.                         Console.WriteLine("Card not found.");
  62.                     }
  63.                 }
  64.                 else if (command == "Swap")
  65.                 {
  66.                     string word2 = array[2];
  67.                     indexRem = cardN.IndexOf(cardName);
  68.                     int newIndex = cardN.IndexOf(word2);
  69.                    
  70.                    
  71.                     if (indexRem > newIndex)
  72.                     {
  73.                         cardN.Insert(indexRem, word2);
  74.                         cardN.RemoveAt(indexRem + 1);
  75.                         cardN.Insert(newIndex, cardName);
  76.                         cardN.RemoveAt(newIndex + 1);
  77.                     }
  78.                     else
  79.                     {
  80.                         cardN.Insert(newIndex, cardName);
  81.                         cardN.RemoveAt(newIndex + 1);
  82.                         cardN.Insert(indexRem, word2);
  83.                         cardN.RemoveAt(indexRem + 1);
  84.                     }
  85.                 }
  86.                 else if (command == "Shuffle")
  87.                 {
  88.                     cardN.Reverse();
  89.                    
  90.                 }
  91.             }
  92.             Console.WriteLine(string.Join(" ", cardN));
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement