Advertisement
Vladimir76

Hornet Armada -2

Feb 28th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Task_4
  8. {
  9.    
  10.  
  11.     class Program
  12.     {
  13.         static void AddingLegionAndActivity(Dictionary<string, long> dicLegion,
  14.             string currentNameLeg, long currentActiv)
  15.         {
  16.             if (!dicLegion.ContainsKey(currentNameLeg))
  17.             {
  18.                 dicLegion.Add(currentNameLeg, currentActiv);
  19.             }
  20.             else
  21.             {
  22.                 if (dicLegion[currentNameLeg] < currentActiv)
  23.                 {
  24.                     dicLegion[currentNameLeg] = currentActiv;
  25.                 }
  26.             }
  27.         }
  28.  
  29.         static void AddingTypeSoldierAndLegion(Dictionary<string, Dictionary<string, long>> dicTypeSoldier,
  30.             string currentNameLeg, string currentSoldierType, long currentCountSold)
  31.         {
  32.             if (!dicTypeSoldier.ContainsKey(currentNameLeg))
  33.             {
  34.                 dicTypeSoldier.Add(currentNameLeg, new Dictionary<string, long>());
  35.                 dicTypeSoldier[currentNameLeg].Add(currentSoldierType, currentCountSold);
  36.             }
  37.             else if (dicTypeSoldier.ContainsKey(currentNameLeg) &&
  38.                 !dicTypeSoldier[currentNameLeg].ContainsKey(currentSoldierType))
  39.             {
  40.                 dicTypeSoldier[currentNameLeg].Add(currentSoldierType, currentCountSold);
  41.             }
  42.             else if (dicTypeSoldier.ContainsKey(currentNameLeg) &&
  43.                 dicTypeSoldier[currentNameLeg].ContainsKey(currentSoldierType))
  44.             {
  45.                 dicTypeSoldier[currentNameLeg][currentSoldierType] += currentCountSold;
  46.             }
  47.            
  48.         }
  49.  
  50.         static void Main()
  51.         {
  52.             Dictionary<string, long> dicLegion = new Dictionary<string, long>();
  53.             Dictionary<string, Dictionary<string, long>> dicTypeSoldier =
  54.                 new Dictionary<string, Dictionary<string, long>>();
  55.             Dictionary<string, long> dicBuffer = new Dictionary<string, long>();
  56.  
  57.             long num = long.Parse(Console.ReadLine());
  58.  
  59.             for (int i = 0; i < num; i++)
  60.             {
  61.                 string[] input = Console.ReadLine()
  62.                     .Trim()
  63.                     .Split(new char[] { '=', '-', '>', ':', ' ' },
  64.                              StringSplitOptions.RemoveEmptyEntries)
  65.                     .ToArray();
  66.  
  67.                 long currentActiv = long.Parse(input[0]);
  68.                 string currentNameLeg = input[1];
  69.                 string currentSoldierType = input[2];
  70.                 long currentCountSold = long.Parse(input[3]);
  71.                 AddingLegionAndActivity(dicLegion,currentNameLeg, currentActiv);
  72.                 AddingTypeSoldierAndLegion(dicTypeSoldier, currentNameLeg, currentSoldierType, currentCountSold);
  73.                
  74.             }
  75.             string[] output = Console.ReadLine().Split('\\');
  76.             if (output.Length > 1)
  77.             {
  78.                 long searchActivity = long.Parse(output[0]);
  79.                 string searchTypeSoldier = output[1];
  80.  
  81.                 foreach (KeyValuePair<string,long> kvp in dicLegion)
  82.                 {
  83.                     string legion;
  84.                     if (kvp.Value < searchActivity)
  85.                     {
  86.                         legion = kvp.Key;
  87.                         foreach (KeyValuePair<string,Dictionary<string,long>> kvpkvp in dicTypeSoldier)
  88.                         {
  89.                             if (kvpkvp.Key == legion)
  90.                             {
  91.                                 foreach (var kk in kvpkvp.Value)
  92.                                 {
  93.                                     if (kk.Key == searchTypeSoldier)
  94.                                     {
  95.                                         dicBuffer.Add(kvpkvp.Key, kk.Value);
  96.                                     }
  97.                                 }
  98.                             }
  99.                         }
  100.                     }
  101.                 }
  102.                 foreach (KeyValuePair<string,long> kvp in dicBuffer.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  103.                 {
  104.                     Console.WriteLine("{0} -> {1}",kvp.Key,kvp.Value);
  105.                 }
  106.             }
  107.             else
  108.             {
  109.                 string soldier = output[0];
  110.                 string leg = null;
  111.                 foreach (KeyValuePair<string,Dictionary<string,long>> kvp in dicTypeSoldier)
  112.                 {
  113.                     if (kvp.Value.ContainsKey(soldier))
  114.                     {
  115.                         leg = kvp.Key;
  116.                         foreach (KeyValuePair<string, long> result in dicLegion)
  117.                         {
  118.                             if (result.Key == leg)
  119.                             {
  120.                                 dicBuffer.Add(result.Key, result.Value);
  121.                             }
  122.                         }
  123.                     }
  124.                    
  125.                 }
  126.                 foreach (KeyValuePair<string, long> res in dicBuffer.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  127.                 {
  128.                     Console.WriteLine("{0} : {1}",res.Value,res.Key);
  129.                 }
  130.             }
  131.         }      
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement