Advertisement
desislava_topuzakova

06. Songs Queue

May 17th, 2022
797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace SongsQueue
  5. {
  6.     internal class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Queue<string> songsQueue = new Queue<string>(Console.ReadLine().Split(", "));
  11.  
  12.             //stop: песните свършат
  13.             //продължаваме: имаме песни
  14.  
  15.             while (songsQueue.Count > 0)
  16.             {
  17.                 //изпълнявам команда
  18.                 string command = Console.ReadLine();
  19.                 //"Play"
  20.                 if (command == "Play")
  21.                 {
  22.                     songsQueue.Dequeue(); //пускаме първата песен
  23.                 }
  24.                 //"Add {song}".Split() -> ["Add", "{song}"]
  25.                 else if (command.Contains("Add"))
  26.                 {
  27.                     //"Add Watch Me"
  28.                     string song = command.Substring(4);
  29.                     //да я има -> "{song} is already contained!"
  30.                     if (songsQueue.Contains(song))
  31.                     {
  32.                         Console.WriteLine($"{song} is already contained!");
  33.                     }
  34.                     //да я няма -> слагаме на опашката
  35.                     else
  36.                     {
  37.                         songsQueue.Enqueue(song);
  38.  
  39.                     }
  40.                 }
  41.                 //"Show"
  42.                 else if (command == "Show")
  43.                 {
  44.                     Console.WriteLine(string.Join(", ", songsQueue));
  45.                 }
  46.             }
  47.  
  48.             Console.WriteLine("No more songs!");
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement