Advertisement
Guest User

Untitled

a guest
May 30th, 2019
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ClubParty
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int n = int.Parse(Console.ReadLine());
  12.  
  13. var hall = new Dictionary<string, List<int>>();
  14.  
  15. var line = Console.ReadLine().Split(' ' , StringSplitOptions.RemoveEmptyEntries).Reverse().ToList();
  16.  
  17. int capacity = 0;
  18.  
  19. for (int i = 0; i < line.Count; i++)
  20. {
  21.  
  22. if (int.TryParse(line[i] , out int number) && hall.Count > 0)
  23. {
  24. capacity += number;
  25. if(capacity <= n)
  26. {
  27. var hallNumber = hall.Keys.First();
  28. hall[hallNumber].Add(int.Parse(line[i]));
  29. }
  30. else if (hall.Count > 0)
  31. {
  32. foreach (var (key, value) in hall)
  33. {
  34. if (value.Count > 0)
  35. {
  36. Console.Write($"{key} -> ");
  37. Console.Write(string.Join(", ", value));
  38. Console.WriteLine();
  39. hall.Remove(key);
  40. capacity = 0;
  41. break;
  42. }
  43. else
  44. {
  45. capacity -= number;
  46. }
  47.  
  48. }
  49. if (hall.Count > 0 && number <= n)
  50. {
  51. var hallNumber = hall.Keys.First();
  52. hall[hallNumber].Add(int.Parse(line[i]));
  53. capacity += number;
  54. }
  55. }
  56. }
  57.  
  58. else
  59. {
  60. if (!hall.ContainsKey(line[i]) && char.TryParse(line[i] , out char result))
  61. {
  62. if (char.IsLetter(result))
  63. {
  64. hall[line[i]] = new List<int>();
  65. }
  66. }
  67. }
  68. }
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement