Advertisement
XfreeBG

Untitled

Jan 7th, 2023
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. List<string> toBeInserted = new List<string>();
  2.             List<string> inputs = Console.ReadLine().Split(" ").ToList(); //1 2 4 5 6 7
  3.             List<string> outputs = new List<string>();
  4.            
  5.  
  6.             while (true)
  7.             {
  8.                 List<string> UserCommands = Console.ReadLine().Split(" ").ToList(); //contains 1
  9.                 if (UserCommands[0] == "add")
  10.                 {
  11.                     inputs.Insert(int.Parse(UserCommands[1]), UserCommands[2]);
  12.                 }
  13.                 else if(UserCommands[0] == "addMany")
  14.                 {
  15.                     toBeInserted.Clear();
  16.                     for (int a = 2; a < UserCommands.Count; a++)
  17.                     {                      
  18.                         toBeInserted.Add(UserCommands[a]);
  19.                        
  20.                     }
  21.                     inputs.InsertRange(int.Parse(UserCommands[1]), toBeInserted);
  22.                 }
  23.                 else if(UserCommands[0] == "contains")
  24.                 {
  25.                     string printContains = string.Empty;
  26.                     for (int b = 0; b < inputs.Count; b++)
  27.                     {
  28.                         if (inputs[b] == UserCommands[1])
  29.                         {
  30.                             printContains = b.ToString();
  31.                         }                      
  32.                     }
  33.                     if(printContains == string.Empty)
  34.                     {
  35.                         outputs.Add("-1");
  36.                     }
  37.                     else
  38.                     {
  39.                         outputs.Add(printContains);
  40.                     }
  41.                 }
  42.                 else if(UserCommands[0] == "print")
  43.                 {
  44.                     foreach(string smth2 in outputs)
  45.                     {
  46.                         Console.WriteLine(smth2);
  47.                     }
  48.                     foreach (string smth in inputs)
  49.                     {
  50.                         Console.Write(smth + " ");
  51.                     }
  52.                     break;
  53.                 }
  54.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement