Advertisement
Guest User

Untitled

a guest
May 22nd, 2020
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace QueuesAndStacks
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string[] inputSongs = Console.ReadLine().Split(", ").ToArray();
  12.             Queue<string> songsQueue = new Queue<string>();
  13.             string[] comanda = Console.ReadLine().Split(" ").ToArray();
  14.          
  15.             for (int i = 0; i < inputSongs.Length; i++)
  16.             {
  17.                 songsQueue.Enqueue(inputSongs[i]);
  18.             }
  19.  
  20.             while (songsQueue.Any())
  21.             {
  22.                 if (comanda[0] == "Play")
  23.                 {
  24.                      songsQueue.Dequeue();
  25.                 }
  26.                 else if (comanda[0] == "Add")
  27.                 {
  28.                     string[] songName = new string[comanda.Length - 1];
  29.                     for (int i = 0; i < songName.Length; i++)
  30.                     {
  31.                         songName[i] = comanda[i + 1];
  32.                     }
  33.                     string songFullname = string.Join(" ",songName);
  34.                     if (songsQueue.Contains(songFullname))
  35.                     {
  36.                         Console.WriteLine($"{songFullname} is already contained! ");
  37.                     }
  38.                     else
  39.                     {
  40.                         songsQueue.Enqueue(songFullname);
  41.                     }
  42.  
  43.                 }
  44.                 else if (comanda[0] == "Show")
  45.                 {
  46.                     Console.WriteLine("{0}", string.Join(", ", songsQueue));
  47.                 }
  48.  
  49.                 comanda = Console.ReadLine().Split(" ").ToArray();
  50.             }
  51.  
  52.             if (!songsQueue.Any())
  53.             {
  54.                 Console.WriteLine("No more songs!");
  55.             }
  56.  
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement