Advertisement
Vladimir76

Hornet Armada

Feb 27th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.83 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.     class Hornet
  10.     {
  11.         public int Activity { get; set; }
  12.         public string LegionName { get; set; }
  13.         public string SoldierType { get; set; }
  14.         public int SoldierCount { get; set; }
  15.     }
  16.  
  17.     class Program
  18.     {
  19.         static void Main()
  20.         {
  21.             List<Hornet> hornets = new List<Hornet>();
  22.             Dictionary<string, int> dicType = new Dictionary<string, int>();
  23.             int num = int.Parse(Console.ReadLine());
  24.             bool check = true;
  25.  
  26.             for (int i = 0; i < num; i++)
  27.             {
  28.                 string[] input = Console.ReadLine()
  29.                     .Trim()
  30.                     .Split(new char[] { '=', '-', '>', ':', ' ' },
  31.                              StringSplitOptions.RemoveEmptyEntries)
  32.                     .ToArray();
  33.  
  34.                 int currentActiv = int.Parse(input[0]);
  35.                 string currentNameLeg = input[1];
  36.                 string currentSoldierType = input[2];
  37.                 int currentCountSold = int.Parse(input[3]);
  38.                 Hornet hornet = new Hornet();
  39.                 hornet.Activity = currentActiv;
  40.                 hornet.LegionName = currentNameLeg;
  41.                 hornet.SoldierType = currentSoldierType;
  42.                 hornet.SoldierCount = currentCountSold;
  43.                 hornets.Add(hornet);
  44.                
  45.             }
  46.             string[] output = Console.ReadLine().Split('\\');
  47.             string searchSoldType;
  48.             if (output.Length > 1)
  49.             {
  50.                 int searchAct = int.Parse(output[0]);
  51.                 searchSoldType = output[1];
  52.                 foreach (var act in hornets)
  53.                 {
  54.                     if (act.Activity < searchAct)
  55.                     {
  56.                         if (!dicType.ContainsKey(act.LegionName))
  57.                         {
  58.                             dicType.Add(act.LegionName, act.SoldierCount);
  59.                         }
  60.                         else if (dicType.ContainsKey(act.LegionName) && act.SoldierType == searchSoldType)
  61.                         {
  62.                             dicType[act.LegionName] += act.SoldierCount;
  63.                         }
  64.                     }
  65.                 }
  66.                
  67.             }
  68.             else
  69.             {
  70.                 searchSoldType = output[0];
  71.                 foreach (var marbar in hornets)                           // the variables are as terrible task//
  72.                 {
  73.                     if (marbar.SoldierType == searchSoldType)
  74.                     {
  75.                         string leg = marbar.LegionName;
  76.                         int numb = marbar.Activity;        
  77.                         foreach (var mar in hornets)
  78.                         {
  79.                             if (mar.LegionName == leg && mar.Activity > numb)
  80.                             {
  81.                                 numb = mar.Activity;
  82.                             }
  83.                         }
  84.                         dicType.Add(leg, numb);                         // the variables are as terrible task//
  85.                     }
  86.                 }
  87.                 check = false;
  88.             }
  89.             var sortDicType = dicType.OrderByDescending(x => x.Value).ThenBy(x => x.Key);
  90.             if (check)
  91.             {
  92.                 foreach (KeyValuePair<string,int> kvp in sortDicType)
  93.                 {
  94.                     Console.WriteLine("{0} -> {1}",kvp.Key,kvp.Value);
  95.                 }
  96.             }
  97.             else
  98.             {
  99.                 foreach (KeyValuePair<string, int> kvp in sortDicType)
  100.                 {
  101.                     Console.WriteLine("{0} : {1}",kvp.Value,kvp.Key);
  102.                 }
  103.             }
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement