Advertisement
gospod1978

MidExam/Group2/Weaponsmith

Nov 12th, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. namespace fundamental14
  7. {
  8.     class MainClass
  9.     {
  10.         public static void Main()
  11.         {
  12.             List<string> weapon = Console.ReadLine().Split("|").ToList();
  13.             string input = string.Empty;
  14.            
  15.             while((input = Console.ReadLine()) != "Done")
  16.             {
  17.                 string[] array = input.Split().ToArray();
  18.                 string command = array[0];
  19.                 string position = array[1];
  20.                
  21.                 if(command == "Move")
  22.                 {
  23.                     int index = int.Parse(array[2]);
  24.                     if (index >= 0 && index < weapon.Count)
  25.             {      
  26.                     if (position == "Left")
  27.                     {
  28.                         if (index > 0 && index < weapon.Count)
  29.                         {
  30.                             string current = weapon[index - 1];
  31.                             weapon.RemoveAt(index - 1);
  32.                             weapon.Insert(index, current);
  33.                         }
  34.                     }
  35.                     else
  36.                     {
  37.                         if (index >= 0 && index < weapon.Count - 1)
  38.                         {
  39.                            
  40.                        
  41.                             string newCurrent = weapon[index];
  42.                             weapon.RemoveAt(index);
  43.                             weapon.Insert(index + 1, newCurrent);
  44.                        
  45.                            
  46.                         }
  47.                     }
  48.                     }
  49.                 }
  50.                 else
  51.                 {
  52.                     if (position == "Odd")
  53.                     {
  54.                         for (int i = 0; i < weapon.Count; i++)
  55.                         {
  56.                             if (i % 2 != 0)
  57.                             {
  58.                                 Console.Write($"{weapon[i]} ");
  59.                             }
  60.                         }
  61.                         Console.WriteLine(" ");
  62.                     }
  63.                     else
  64.                     {
  65.                         for (int i = 0; i < weapon.Count; i++)
  66.                         {
  67.                             if (i % 2 == 0)
  68.                             {
  69.                                 Console.Write($"{weapon[i]} ");
  70.                             }
  71.                         }
  72.                         Console.WriteLine(" ");
  73.                     }
  74.                 }
  75.             }
  76.             StringBuilder sb = new StringBuilder();
  77.             foreach (var kvp in weapon)
  78.             {
  79.                 sb.Append(kvp);
  80.             }
  81.            
  82.             Console.WriteLine($"You crafted {sb}!");
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement