Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. namespace Problem_6.Songs_Queue
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text;
  7.     using System.Threading.Tasks;
  8.  
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             var inputSongs = Console.ReadLine()
  14.                 .Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries)
  15.                 .ToArray();
  16.             var songQueue = new Queue<string>(inputSongs);
  17.             while (true)
  18.             {
  19.                 var command = Console.ReadLine().Split(new char[] { ' ' },2).ToArray();
  20.  
  21.                 if (command[0] == "Play")
  22.                 {
  23.                     if (songQueue.Count > 0)
  24.                     {
  25.                         songQueue.Dequeue();
  26.                     }
  27.                     else
  28.                     {
  29.                         Console.WriteLine("No more songs!");
  30.                         continue;
  31.                     }
  32.                 }
  33.  
  34.                 else if (command[0] == "Add")
  35.                 {
  36.                     if (songQueue.Contains(command[1]))
  37.                     {
  38.                         Console.WriteLine($"{command[1]} is already contained!");
  39.                     }
  40.                     else
  41.                     {
  42.                         songQueue.Enqueue(command[1]);
  43.                     }
  44.                 }
  45.                 else if (command[0] == "Show")
  46.                 {
  47.                     Console.WriteLine(String.Join(", ", songQueue));
  48.                 }
  49.  
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement