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 Hornet
- {
- public int Activity { get; set; }
- public string LegionName { get; set; }
- public string SoldierType { get; set; }
- public int SoldierCount { get; set; }
- }
- class Program
- {
- static void Main()
- {
- List<Hornet> hornets = new List<Hornet>();
- Dictionary<string, int> dicType = new Dictionary<string, int>();
- int num = int.Parse(Console.ReadLine());
- bool check = true;
- for (int i = 0; i < num; i++)
- {
- string[] input = Console.ReadLine()
- .Trim()
- .Split(new char[] { '=', '-', '>', ':', ' ' },
- StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- int currentActiv = int.Parse(input[0]);
- string currentNameLeg = input[1];
- string currentSoldierType = input[2];
- int currentCountSold = int.Parse(input[3]);
- Hornet hornet = new Hornet();
- hornet.Activity = currentActiv;
- hornet.LegionName = currentNameLeg;
- hornet.SoldierType = currentSoldierType;
- hornet.SoldierCount = currentCountSold;
- hornets.Add(hornet);
- }
- string[] output = Console.ReadLine().Split('\\');
- string searchSoldType;
- if (output.Length > 1)
- {
- int searchAct = int.Parse(output[0]);
- searchSoldType = output[1];
- foreach (var act in hornets)
- {
- if (act.Activity < searchAct)
- {
- if (!dicType.ContainsKey(act.LegionName))
- {
- dicType.Add(act.LegionName, act.SoldierCount);
- }
- else if (dicType.ContainsKey(act.LegionName) && act.SoldierType == searchSoldType)
- {
- dicType[act.LegionName] += act.SoldierCount;
- }
- }
- }
- }
- else
- {
- searchSoldType = output[0];
- foreach (var marbar in hornets) // the variables are as terrible task//
- {
- if (marbar.SoldierType == searchSoldType)
- {
- string leg = marbar.LegionName;
- int numb = marbar.Activity;
- foreach (var mar in hornets)
- {
- if (mar.LegionName == leg && mar.Activity > numb)
- {
- numb = mar.Activity;
- }
- }
- dicType.Add(leg, numb); // the variables are as terrible task//
- }
- }
- check = false;
- }
- var sortDicType = dicType.OrderByDescending(x => x.Value).ThenBy(x => x.Key);
- if (check)
- {
- foreach (KeyValuePair<string,int> kvp in sortDicType)
- {
- Console.WriteLine("{0} -> {1}",kvp.Key,kvp.Value);
- }
- }
- else
- {
- foreach (KeyValuePair<string, int> kvp in sortDicType)
- {
- Console.WriteLine("{0} : {1}",kvp.Value,kvp.Key);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement