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 Task_4
- {
- class Program
- {
- static void AddingLegionAndActivity(Dictionary<string, long> dicLegion,
- string currentNameLeg, long currentActiv)
- {
- if (!dicLegion.ContainsKey(currentNameLeg))
- {
- dicLegion.Add(currentNameLeg, currentActiv);
- }
- else
- {
- if (dicLegion[currentNameLeg] < currentActiv)
- {
- dicLegion[currentNameLeg] = currentActiv;
- }
- }
- }
- static void AddingTypeSoldierAndLegion(Dictionary<string, Dictionary<string, long>> dicTypeSoldier,
- string currentNameLeg, string currentSoldierType, long currentCountSold)
- {
- if (!dicTypeSoldier.ContainsKey(currentNameLeg))
- {
- dicTypeSoldier.Add(currentNameLeg, new Dictionary<string, long>());
- dicTypeSoldier[currentNameLeg].Add(currentSoldierType, currentCountSold);
- }
- else if (dicTypeSoldier.ContainsKey(currentNameLeg) &&
- !dicTypeSoldier[currentNameLeg].ContainsKey(currentSoldierType))
- {
- dicTypeSoldier[currentNameLeg].Add(currentSoldierType, currentCountSold);
- }
- else if (dicTypeSoldier.ContainsKey(currentNameLeg) &&
- dicTypeSoldier[currentNameLeg].ContainsKey(currentSoldierType))
- {
- dicTypeSoldier[currentNameLeg][currentSoldierType] += currentCountSold;
- }
- }
- static void Main()
- {
- Dictionary<string, long> dicLegion = new Dictionary<string, long>();
- Dictionary<string, Dictionary<string, long>> dicTypeSoldier =
- new Dictionary<string, Dictionary<string, long>>();
- Dictionary<string, long> dicBuffer = new Dictionary<string, long>();
- long num = long.Parse(Console.ReadLine());
- for (int i = 0; i < num; i++)
- {
- string[] input = Console.ReadLine()
- .Trim()
- .Split(new char[] { '=', '-', '>', ':', ' ' },
- StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- long currentActiv = long.Parse(input[0]);
- string currentNameLeg = input[1];
- string currentSoldierType = input[2];
- long currentCountSold = long.Parse(input[3]);
- AddingLegionAndActivity(dicLegion,currentNameLeg, currentActiv);
- AddingTypeSoldierAndLegion(dicTypeSoldier, currentNameLeg, currentSoldierType, currentCountSold);
- }
- string[] output = Console.ReadLine().Split('\\');
- if (output.Length > 1)
- {
- long searchActivity = long.Parse(output[0]);
- string searchTypeSoldier = output[1];
- foreach (KeyValuePair<string,long> kvp in dicLegion)
- {
- string legion;
- if (kvp.Value < searchActivity)
- {
- legion = kvp.Key;
- foreach (KeyValuePair<string,Dictionary<string,long>> kvpkvp in dicTypeSoldier)
- {
- if (kvpkvp.Key == legion)
- {
- foreach (var kk in kvpkvp.Value)
- {
- if (kk.Key == searchTypeSoldier)
- {
- dicBuffer.Add(kvpkvp.Key, kk.Value);
- }
- }
- }
- }
- }
- }
- foreach (KeyValuePair<string,long> kvp in dicBuffer.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- Console.WriteLine("{0} -> {1}",kvp.Key,kvp.Value);
- }
- }
- else
- {
- string soldier = output[0];
- string leg = null;
- foreach (KeyValuePair<string,Dictionary<string,long>> kvp in dicTypeSoldier)
- {
- if (kvp.Value.ContainsKey(soldier))
- {
- leg = kvp.Key;
- foreach (KeyValuePair<string, long> result in dicLegion)
- {
- if (result.Key == leg)
- {
- dicBuffer.Add(result.Key, result.Value);
- }
- }
- }
- }
- foreach (KeyValuePair<string, long> res in dicBuffer.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- Console.WriteLine("{0} : {1}",res.Value,res.Key);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement