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.Threading.Tasks;
- namespace _06.HornetArmada
- {
- class HornetArmada
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- List<string> lines = new List<string>();
- for (int i = 0; i < n; i++)
- {
- string line = Console.ReadLine();
- lines.Add(line);
- }
- string search = Console.ReadLine();
- string[] tokens = search.Split('\\');
- if (tokens.Length>1)
- {
- long lastA = long.Parse(tokens[0]);
- string soldier = tokens[1];
- Dictionary<string, long> legionData = new Dictionary<string, long>();
- foreach (var sentence in lines)
- {
- string[] paramsOfLine = sentence.Split(new char[] { ' ', '>', '=', '-', ':' }, StringSplitOptions.RemoveEmptyEntries);
- long legionLastA = long.Parse(paramsOfLine[0]);
- if (legionLastA < lastA && sentence.Contains(soldier) )
- {
- string legion = paramsOfLine[1];
- long countOfSold = long.Parse(paramsOfLine[3]);
- if (!legionData.ContainsKey(legion))
- {
- legionData[legion] = 0;
- }
- legionData[legion] += countOfSold;
- }
- }
- foreach (var some in legionData.OrderByDescending(a=>a.Value))
- {
- string leg = some.Key;
- long sldCount = some.Value;
- Console.WriteLine($"{leg} -> {sldCount}");
- }
- }
- else
- {
- Dictionary<string, Dictionary<string, long>> lastALegionData = new Dictionary<string, Dictionary<string, long>>();
- string sld = tokens[0];
- foreach (var sentence in lines)
- {
- string[] paramsOfLine = sentence.Split(new char[] { ' ', '>', '=', '-', ':' }, StringSplitOptions.RemoveEmptyEntries);
- long lastA = long.Parse(paramsOfLine[0]);
- string legionN = paramsOfLine[1];
- string soldier = paramsOfLine[2];
- if (!lastALegionData.ContainsKey(legionN))
- {
- lastALegionData[legionN] = new Dictionary<string, long>();
- }
- if (!lastALegionData[legionN].ContainsKey(soldier))
- {
- lastALegionData[legionN][soldier] = 0;
- }
- if (lastALegionData[legionN][soldier]<lastA)
- {
- lastALegionData[legionN][soldier] = lastA;
- }
- }
- foreach (var item in lastALegionData.Where(x=>x.Value.ContainsKey(sld)).OrderByDescending(a=>a.Value.Values.Max()))
- {
- string legionN = item.Key;
- //if (lastALegionData[legionN].ContainsKey(sld))
- //{
- Console.WriteLine($"{item.Value.Values.Max()} : {legionN}");
- //}
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement