Advertisement
Guest User

EasterGifts

a guest
Feb 22nd, 2020
131
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. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Easter_gift
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<string> gifts = Console.ReadLine().Split().ToList();
  14.  
  15.             string command = string.Empty;
  16.             while((command=(Console.ReadLine()))!="No Money")
  17.             {
  18.                 string[] parts = command.Split();
  19.                 string action=parts[0];
  20.                 string product=parts[1];
  21.                
  22.                
  23.                 if(action=="OutOfStock")
  24.                 {
  25.                     string gift="None";
  26.                     if(gifts.Contains(product))
  27.                     {
  28.                         for (int i= 0; i < gifts.Count; i++)
  29.                         {
  30.                             if(gifts[i]==product)
  31.                             {
  32.                                 gifts[i]=gift;
  33.                             }
  34.                         }
  35.                     }
  36.                 }
  37.                 else if(action=="Required")
  38.                 {
  39.                     int index=int.Parse(parts[2]);
  40.                     if(index>=0 && index<gifts.Count)
  41.                     {
  42.                         gifts[index] = product;
  43.                     }                    
  44.                 }
  45.                 else if(action=="JustInCase")
  46.                 {
  47.                     gifts[gifts.Count - 1] = product;
  48.                 }
  49.             }
  50.             for (int i = 0; i < gifts.Count; i++)
  51.             {
  52.                 if(gifts[i]!="None")
  53.                 {
  54.                     Console.Write(gifts[i]+" ");
  55.                 }
  56.             }
  57.            
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement