Advertisement
ralichka

Exam-16.04.2019-02.EasterGifts

Oct 31st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02.EasterGifts
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> gifts = Console.ReadLine().Split().ToList();
  12.  
  13.             string[] command = Console.ReadLine().Split();
  14.             string word = command[0];
  15.  
  16.             while (word != "No")
  17.             {
  18.                 if (word == "OutOfStock")
  19.                 {
  20.                     string giftName = command[1];
  21.                     for (int i = 0; i < gifts.Count; i++)
  22.                     {
  23.                         if (gifts[i] == giftName)
  24.                         {
  25.                             gifts[i] = "None";
  26.                         }
  27.                     }
  28.                 }
  29.                 else if (word == "Required")
  30.                 {
  31.                     string giftName = command[1];
  32.                     int index = int.Parse(command[2]);
  33.  
  34.                     if (index >= 0 && index < gifts.Count)
  35.                     {
  36.                         gifts[index] = giftName;
  37.                     }
  38.                 }
  39.                 else if (word == "JustInCase")
  40.                 {
  41.                     string giftName = command[1];
  42.                     gifts[gifts.Count - 1] = giftName;
  43.                 }
  44.                 command = Console.ReadLine().Split();
  45.                 word = command[0];
  46.             }
  47.             List<string> finalGifts = new List<string>();
  48.  
  49.             for (int i = 0; i < gifts.Count; i++)
  50.             {
  51.                 if (gifts[i] != "None")
  52.                 {
  53.                     finalGifts.Add(gifts[i]);
  54.                 }
  55.             }
  56.             Console.WriteLine(string.Join(" ", finalGifts));
  57.  
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement