alexbancheva

Last_Stop_MidExam_Lists_10thOfMarch2019

Apr 13th, 2020
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.61 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Last_Stop_MidExam_Lists_10thOfMarch2019
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> paintingNums = Console.ReadLine()
  12.                 .Split(" ")
  13.                 .Select(x => int.Parse(x))
  14.                 .ToList();
  15.  
  16.             string instruction = Console.ReadLine();
  17.  
  18.            // List<int> reversedPaintingNums = new List<int>();
  19.  
  20.             while (instruction != "END")
  21.             {
  22.                 string[] splitedCommand = instruction.Split(" ");
  23.                 string command = splitedCommand[0];
  24.  
  25.                 if (command == "Change")
  26.                 {
  27.                     int paintingNum = int.Parse(splitedCommand[1]);
  28.                     int changedNum = int.Parse(splitedCommand[2]);
  29.  
  30.                    // for (int i = 0; i < paintingNums.Count; i++)
  31.                     //{
  32.                         if (paintingNums.Contains(paintingNum)) //&& paintingNums.Contains(changedNum))
  33.                         {
  34.                             // paintingNum = changedNum;
  35.                             int indexOf1 = paintingNums.IndexOf(paintingNum);
  36.                             // int indexOf2 = paintingNums.IndexOf(changedNum);
  37.  
  38.                             paintingNums[indexOf1] = changedNum;
  39.                            // paintingNums[indexOf2] = paintingNum;
  40.                         }
  41.                    // }
  42.                    
  43.                 }
  44.                 else if (command == "Hide")
  45.                 {
  46.                     int paintingNum = int.Parse(splitedCommand[1]);
  47.  
  48.                     //for (int i = 0; i < paintingNums.Count; i++)
  49.                   //  {
  50.                         if (paintingNums.Contains(paintingNum))
  51.                         {
  52.                             paintingNums.Remove(paintingNum);
  53.                         }
  54.                    // }
  55.                 }
  56.                 else if (command == "Switch")
  57.                 {
  58.                     int paintingNum = int.Parse(splitedCommand[1]);
  59.                     int paintingNumSec = int.Parse(splitedCommand[2]);
  60.  
  61.                   //  for (int i = 0; i < paintingNums.Count; i++)
  62.                    // {
  63.                         if (paintingNums.Contains(paintingNum) && paintingNums.Contains(paintingNumSec))
  64.                         {
  65.                             int indexOf1 = paintingNums.IndexOf(paintingNum);
  66.                             int indexOf2 = paintingNums.IndexOf(paintingNumSec);
  67.  
  68.                             paintingNums[indexOf1] = paintingNumSec;
  69.                             paintingNums[indexOf2] = paintingNum;
  70.                         }
  71.                    // }
  72.                 }
  73.                 else if (command == "Insert")
  74.                 {
  75.                     int place = int.Parse(splitedCommand[1]) + 1;
  76.                     int paintingNum = int.Parse(splitedCommand[2]);
  77.                    // for (int i = 0; i < paintingNums.Count; i++)
  78.                     //{
  79.                         if (place > 0 && place <= paintingNums.Count)
  80.                         {
  81.                             paintingNums.Insert(place, paintingNum);
  82.                         }
  83.                     //}
  84.  
  85.                 }
  86.                 else if (command == "Reverse")
  87.                 {
  88.                     paintingNums.Reverse();
  89.                 }
  90.  
  91.                 instruction = Console.ReadLine();
  92.             }
  93.  
  94.             if (instruction == "END")
  95.             {
  96.                 Console.WriteLine(string.Join(" ", paintingNums));
  97.             }
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment