Advertisement
MartinGeorgiev

Songs Queue

Jan 12th, 2023
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         string[] songs = Console.ReadLine().Split(", ");
  9.         Queue<string> songQueue = new Queue<string>(songs);
  10.  
  11.         while (songQueue.Count > 0)
  12.         {
  13.             string[] command = Console.ReadLine().Split();
  14.  
  15.             if (command[0] == "Play")
  16.             {
  17.                 songQueue.Dequeue();
  18.             }
  19.             else if (command[0] == "Add")
  20.             {
  21.                 string song = string.Join(" ",command, 1, command.Length -1);
  22.                
  23.                 if (songQueue.Contains(song))
  24.                 {
  25.                     Console.WriteLine($"{song} is already contained!");
  26.                 }
  27.                 else
  28.                 {
  29.                     songQueue.Enqueue(song);
  30.                 }
  31.             }
  32.             else if (command[0] == "Show")
  33.             {
  34.                 Console.WriteLine(string.Join(", ", songQueue));
  35.             }
  36.         }
  37.  
  38.         Console.WriteLine("No more songs!");
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement