Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace SOFTUNI_ADV
- {
- public class StringsSoftUni
- {
- static void Main()
- {
- string[] seps = Console.ReadLine().Split(' ');
- string firstSeparator = seps[0];
- string secondSeparator = seps[1];
- Dictionary<string, int> CoffeeInStock = new Dictionary<string, int>();
- Dictionary<string, string> personPreference = new Dictionary<string, string>();
- string command = Console.ReadLine();
- string firstPart;
- string secondPart;
- while (command != "end of info")
- {
- if (command.Contains(firstSeparator))
- {
- firstPart = command.Substring(0, command.IndexOf(firstSeparator));
- secondPart = command.Substring(command.IndexOf(firstSeparator) + firstSeparator.Length);
- if (personPreference.ContainsKey(firstPart))
- {
- personPreference[firstPart] = secondPart;
- }
- else
- {
- personPreference.Add(firstPart, secondPart);
- }
- if (!CoffeeInStock.ContainsKey(secondPart))
- {
- CoffeeInStock[secondPart] = 0;
- }
- }
- else
- {
- firstPart = command.Substring(0, command.IndexOf(secondSeparator));
- if ((firstPart.Length + firstSeparator.Length) != command.Length)
- {
- secondPart = command.Substring(command.IndexOf(secondSeparator) + secondSeparator.Length);
- }
- else
- {
- secondPart = "0";
- }
- if (CoffeeInStock.ContainsKey(firstPart))
- {
- CoffeeInStock[firstPart] += int.Parse(secondPart) + 0;
- }
- else
- {
- CoffeeInStock.Add(firstPart, int.Parse(secondPart) + 0);
- }
- }
- command = Console.ReadLine();
- }
- command = Console.ReadLine();
- int hasDrinked = 0;
- string type;
- string name;
- foreach (var item in CoffeeInStock)
- {
- if (item.Value == 0)
- {
- Console.WriteLine("Out of {0}", item.Key);
- }
- }
- while (command != "end of week")
- {
- hasDrinked = int.Parse(command.Split(' ')[1]);
- name = command.Split(' ')[0];
- type = personPreference[name];
- CoffeeInStock[type] -= hasDrinked;
- if (CoffeeInStock[type] <= 0)
- {
- Console.WriteLine("Out of {0}", type);
- }
- command = Console.ReadLine();
- }
- Console.WriteLine("Coffee Left:");
- HashSet<string> names = new HashSet<string>();
- foreach (var item in CoffeeInStock.OrderByDescending(x => x.Value))
- {
- if (item.Value > 0)
- {
- names.Add(item.Key);
- Console.WriteLine("{0} {1}", item.Key, item.Value);
- }
- }
- Console.WriteLine("For:");
- foreach (var item in personPreference.OrderBy(x => x.Value).ThenByDescending(x => x.Key))
- {
- if (names.Contains(item.Value))
- {
- Console.WriteLine("{0} {1}", item.Key, item.Value);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement