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 _11_DragonArmy
- {
- class Program
- {
- static void Main()
- {
- var AllData = new Dictionary<string, SortedDictionary<string, Dictionary<string, int>>>();
- var avrData = new Dictionary<string, double[]>();
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- string[] inputLine = GetInput();
- string type = inputLine[0];
- string dragon = inputLine[1];
- int damage = GetStat(inputLine, 45, 2);
- int health = GetStat(inputLine, 250, 3);
- int armor = GetStat(inputLine, 10, 4);
- if (!AllData.ContainsKey(type))
- {
- AllData[type] = new SortedDictionary<string, Dictionary<string, int>>();
- avrData[type] = new double[] { 0.0, 0.0, 0.0 };
- }
- if (!AllData[type].ContainsKey(dragon))
- {
- AllData[type][dragon] = new Dictionary<string, int>()
- {
- { "damage", damage }, { "health", health }, { "armor", armor }
- };
- }
- else
- {
- AllData[type][dragon]["damage"] = damage;
- AllData[type][dragon]["health"] = health;
- AllData[type][dragon]["armor"] = armor;
- }
- }
- foreach (var type in AllData)
- {
- double totalDamage = 0.0;
- double totalHealth = 0.0;
- double totalArmor = 0.0;
- foreach (var dragon in type.Value)
- {
- totalDamage += dragon.Value["damage"];
- totalHealth += dragon.Value["health"];
- totalArmor += dragon.Value["armor"];
- }
- avrData[type.Key][0] = totalDamage / type.Value.Count;
- avrData[type.Key][1] = totalHealth / type.Value.Count;
- avrData[type.Key][2] = totalArmor / type.Value.Count;
- }
- foreach (var type in AllData)
- {
- Console.WriteLine($"{type.Key}::({avrData[type.Key][0]:f2}/{avrData[type.Key][1]:f2}/{avrData[type.Key][2]:f2})");
- foreach (var dragon in type.Value)
- {
- Console.WriteLine($"-{dragon.Key} -> damage: {dragon.Value["damage"]}, health: {dragon.Value["health"]}, armor: {dragon.Value["armor"]}");
- }
- }
- }
- private static int GetStat(string[] inputLine, int defaultValue, int index)
- {
- int stat = 0;
- try
- {
- stat = int.Parse(inputLine[index]);
- }
- catch (Exception)
- {
- stat = defaultValue;
- }
- return stat;
- }
- private static string[] GetInput()
- {
- return Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement