Advertisement
Ivan_Naydenov

Untitled

Aug 29th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace SOFTUNI_ADV
  9. {
  10. public class StringsSoftUni
  11. {
  12. static void Main()
  13. {
  14. string[] seps = Console.ReadLine().Split(' ');
  15. string firstSeparator = seps[0];
  16. string secondSeparator = seps[1];
  17. Dictionary<string, int> CoffeeInStock = new Dictionary<string, int>();
  18. Dictionary<string, string> personPreference = new Dictionary<string, string>();
  19. string command = Console.ReadLine();
  20. string firstPart;
  21. string secondPart;
  22.  
  23. while (command != "end of info")
  24. {
  25. if (command.Contains(firstSeparator))
  26. {
  27. firstPart = command.Substring(0, command.IndexOf(firstSeparator));
  28. secondPart = command.Substring(command.IndexOf(firstSeparator) + firstSeparator.Length);
  29. if (personPreference.ContainsKey(firstPart))
  30. {
  31. personPreference[firstPart] = secondPart;
  32. }
  33.  
  34. else
  35. {
  36. personPreference.Add(firstPart, secondPart);
  37. }
  38. if (!CoffeeInStock.ContainsKey(secondPart))
  39. {
  40. CoffeeInStock[secondPart] = 0;
  41. }
  42. }
  43. else
  44. {
  45. firstPart = command.Substring(0, command.IndexOf(secondSeparator));
  46. if ((firstPart.Length + firstSeparator.Length) != command.Length)
  47. {
  48. secondPart = command.Substring(command.IndexOf(secondSeparator) + secondSeparator.Length);
  49. }
  50. else
  51. {
  52. secondPart = "0";
  53. }
  54. if (CoffeeInStock.ContainsKey(firstPart))
  55. {
  56. CoffeeInStock[firstPart] += int.Parse(secondPart) + 0;
  57. }
  58. else
  59. {
  60. CoffeeInStock.Add(firstPart, int.Parse(secondPart) + 0);
  61. }
  62. }
  63. command = Console.ReadLine();
  64. }
  65. command = Console.ReadLine();
  66. int hasDrinked = 0;
  67. string type;
  68. string name;
  69. foreach (var item in CoffeeInStock)
  70. {
  71. if (item.Value == 0)
  72. {
  73. Console.WriteLine("Out of {0}", item.Key);
  74. }
  75. }
  76. while (command != "end of week")
  77. {
  78. hasDrinked = int.Parse(command.Split(' ')[1]);
  79. name = command.Split(' ')[0];
  80. type = personPreference[name];
  81. CoffeeInStock[type] -= hasDrinked;
  82. if (CoffeeInStock[type] <= 0)
  83. {
  84. Console.WriteLine("Out of {0}", type);
  85. }
  86. command = Console.ReadLine();
  87. }
  88. Console.WriteLine("Coffee Left:");
  89. HashSet<string> names = new HashSet<string>();
  90. foreach (var item in CoffeeInStock.OrderByDescending(x => x.Value))
  91. {
  92. if (item.Value > 0)
  93. {
  94. names.Add(item.Key);
  95. Console.WriteLine("{0} {1}", item.Key, item.Value);
  96. }
  97. }
  98. Console.WriteLine("For:");
  99. foreach (var item in personPreference.OrderBy(x => x.Value).ThenByDescending(x => x.Key))
  100. {
  101. if (names.Contains(item.Value))
  102. {
  103. Console.WriteLine("{0} {1}", item.Key, item.Value);
  104. }
  105. }
  106. }
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement