Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace test
- {
- internal class Program
- {
- private static long goldammountAll;
- private static long gemammountAll;
- private static long cashammountAll;
- private static List<string> storage;
- private static string currtype;
- private static long currammount;
- private static string[] helparray;
- private static Dictionary<string, Dictionary<string, long>> dict;
- private static Dictionary<string, long> output;
- private static void Main(string[] args)
- {
- var inputammount = long.Parse(Console.ReadLine());
- dict = new Dictionary<string, Dictionary<string, long>>();
- output = new Dictionary<string, long>();
- var input = Console.ReadLine().Split(new[] { ' ', '\t', '\n' }, StringSplitOptions.RemoveEmptyEntries).ToArray();//Split() връща масив от отделни букви!!!
- //Провери в Google какво означава White Space
- FillInput(input);
- for (int i = 0; i < storage.Count; i++)
- {
- helparray = storage[i].Split('-');
- FillDic(inputammount);
- }
- FillOutPutDict();
- Print();
- }
- private static void FillOutPutDict()
- {
- //грешни проверки. четете условиет
- if (dict.ContainsKey("Gold"))
- {
- output.Add("Gold", goldammountAll);
- }
- if (dict.ContainsKey("Cash"))
- {
- output.Add("Cash", cashammountAll);
- }
- if (dict.ContainsKey("Gem"))
- {
- output.Add("Gem", gemammountAll);
- }
- }
- private static void Print()
- {
- foreach (var item in output.OrderByDescending(x => x.Value))
- {
- Console.WriteLine($"<{item.Key}> ${item.Value}");
- foreach (var item1 in dict[item.Key].OrderByDescending(x => x.Key).ThenBy(x => x.Value))
- {
- Console.WriteLine($"##{item1.Key} - {item1.Value}");
- }
- }
- }
- private static void FillDic(long inputammount)
- {
- currtype = helparray[0];
- currammount = long.Parse(helparray[1]);
- long predict = goldammountAll + currammount + gemammountAll + cashammountAll;//еднакво за всички проверки
- if (isGold())
- {
- if (dict.ContainsKey("Gold") == false)
- {
- if (predict <= inputammount)
- {
- dict.Add("Gold", new Dictionary<string, long>());
- dict["Gold"].Add(currtype, currammount);
- goldammountAll += currammount;
- }
- }
- else
- {
- if (predict <= inputammount)
- {
- dict["Gold"][currtype] += currammount;
- goldammountAll += currammount;
- }
- }
- }
- if (isGem())
- {
- long currpredict = gemammountAll + currammount;
- if (dict.ContainsKey("Gem") == false)
- {
- if (predict <= inputammount && dict.ContainsKey("Gold") && currpredict <= goldammountAll)
- {
- dict.Add("Gem", new Dictionary<string, long>());
- dict["Gem"].Add(currtype, currammount);
- gemammountAll += currammount;
- }
- }
- else
- {
- if (predict <= inputammount && dict.ContainsKey("Gold") && currpredict <= goldammountAll)
- {
- if (dict["Gem"].ContainsKey(currtype) == false)
- {
- dict["Gem"].Add(currtype, currammount);
- gemammountAll += currammount;
- }
- else
- {
- dict["Gem"][currtype] += currammount;
- gemammountAll += currammount;
- }
- }
- }
- }
- if (isCash())
- {
- long currpredict = cashammountAll + currammount;
- if (dict.ContainsKey("Cash") == false)
- {
- if (predict <= inputammount && dict.ContainsKey("Gem") && currpredict <= gemammountAll)
- {
- dict.Add("Cash", new Dictionary<string, long>());
- dict["Cash"].Add(currtype, currammount);
- cashammountAll += currammount;
- }
- }
- else
- {
- if (predict <= inputammount && dict.ContainsKey("Gem") && currpredict <= gemammountAll)
- {
- if (dict["Cash"].ContainsKey(currtype) == false)
- {
- dict["Cash"].Add(currtype, currammount);
- cashammountAll += currammount;
- }
- else
- {
- dict["Cash"][currtype] += currammount;
- cashammountAll += currammount;
- }
- }
- }
- }
- }
- private static bool isCash()
- {
- return currtype.Length == 3;//опростено
- }
- private static bool isGem()
- {
- var copy = currtype.ToLower();
- return copy.EndsWith("gem") && currtype.Length >= 4;//опростено
- }
- private static bool isGold()
- {
- return currtype == "Gold";//опростено
- }
- private static void FillInput(string[] input)
- {
- storage = new List<string>();
- //string empty = string.Empty; ->ненуно
- for (int i = 0; i < input.Length; i += 2)
- {
- //empty = input[i] + "-" + input[i + 1]; -> ненужно
- storage.Add(input[i] + "-" + input[i + 1]);
- //empty = string.Empty; -> ненужно
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement