Advertisement
Iskrenov84

Numbers

Feb 20th, 2022
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace ExamProblemThree
  7. {
  8.     internal class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.            List<int> numbers = Console.ReadLine()
  13.                 .Split(' ',StringSplitOptions.RemoveEmptyEntries)
  14.                 .Select(int.Parse)
  15.                 .ToList();
  16.            
  17.             string[] command = Console.ReadLine()
  18.                 .Split(' ',StringSplitOptions.RemoveEmptyEntries);
  19.  
  20.  
  21.             while (command[0] != "Finish")
  22.             {
  23.                 switch (command[0])
  24.                 {
  25.                     case "Add":
  26.                         numbers.Add(int.Parse(command[1]));
  27.                         break;
  28.                     case "Remove":
  29.                         if (numbers.Contains(int.Parse(command[1])))
  30.                         {
  31.                             numbers.Remove(int.Parse(command[1]));
  32.                         }
  33.                         break;
  34.                     case "Replace":
  35.                         if (numbers.Contains(int.Parse(command[1])))
  36.                         {
  37.                             for (int i = 0; i < numbers.Count; i++)
  38.                             {
  39.                                 if (numbers[i] == int.Parse(command[1]))
  40.                                 {
  41.                                     numbers[i] = int.Parse(command[2]);
  42.                                     break;
  43.                                 }                              
  44.                             }
  45.                         }                        
  46.                         break;
  47.                     case "Collapse":
  48.                         numbers.RemoveAll(x => x < int.Parse(command[1]));
  49.                         break;                    
  50.                 }
  51.                 command = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
  52.             }
  53.             Console.WriteLine(string.Join(' ',numbers));
  54.         }
  55.     }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement