Advertisement
bullit3189

Club Party

May 28th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. public class Program
  7. {
  8. public static void Main()
  9. {
  10. int maxCapacity = int.Parse(Console.ReadLine());
  11.  
  12. int copyOfMax = maxCapacity;
  13.  
  14. Queue<string> halls = new Queue<string>();
  15. Queue<int> people = new Queue<int>();
  16.  
  17. string[]input =Console.ReadLine().Split();
  18.  
  19. for (int i=input.Length-1; i>=0; i--)
  20. {
  21. string currItem = input[i];
  22.  
  23. if(char.IsLetter(currItem[0]))
  24. {
  25. halls.Enqueue(currItem);
  26. }
  27. else
  28. {
  29. if(halls.Count==0)
  30. {
  31. continue;
  32. }
  33. else
  34. {
  35. int currPeople = int.Parse(currItem);
  36.  
  37. if(maxCapacity-currPeople>=0)
  38. {
  39. maxCapacity-=currPeople;
  40. people.Enqueue(currPeople);
  41. }
  42. else
  43. {
  44. maxCapacity = copyOfMax;
  45. Console.WriteLine("{0} -> {1}",halls.Dequeue(),string.Join(", ",people));
  46. people.Clear();
  47. i++;
  48. }
  49. }
  50. }
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement