Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Heroes III is the best game ever. Everyone loves it and everyone plays it all the time.
- Stamat is no exclusion to this rule. His favorite units in the game are all types of dragons – black, red, gold, azure etc…
- He likes them so much that he gives them names and keeps logs of their stats: damage, health and armor.
- The process of aggregating all the data is quite tedious, so he would like to have a program doing it.
- You need to categorize dragons by their type. For each dragon, identified by name, keep information about his stats.
- Type is preserved as in the order of input, but dragons are sorted alphabetically by name.
- For each type, you should also print the average damage, health and armor of the dragons. For each dragon, print his own stats.
- There may be missing stats in the input, though. If a stat is missing you should assign it default values.
- Default values are as follows: health 250, damage 45, and armor 10. Missing stat will be marked by null.
- The input is in the following format: {type} {name} {damage} {health} {armor}. Any of the integers may be assigned null value.
- If the same dragon is added a second time, the new stats should overwrite the previous ones.
- Two dragons are considered equal if they match by both name and type.
- Input:
- On the first line, you are given number N -> the number of dragons to follow
- On the next N lines you are given input in the above described format. There will be single space separating each element.
- Output:
- Print the aggregated data on the console:
- For each type, print average stats of its dragons in format: {Type}::({damage}/{health}/{armor})
- Damage, health and armor should be rounded to two digits after the decimal separator.
- For each dragon, print its stats in format: -{Name} -> damage: {damage}, health: {health}, armor: {armor}
- Constraints:
- N is in range [1…100]
- The dragon type and name are one word only, starting with capital letter.
- Damage, health and armor are integers in range [0 … 100000] or null.
- */
- namespace Dragon_Army
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- internal static class Dragons
- {
- private static void Main()
- {
- var regex = new Regex(@"([a-zA-Z]+) ([a-zA-Z]+) (null|\d+) (null|\d+) (null|\d+)");
- var typesDragons = new Dictionary<string, SortedDictionary<string, int[]>>();
- var rows = int.Parse(Console.ReadLine());
- for (int i = 0; i < rows; i++)
- {
- var inputLine = Console.ReadLine();
- var type = string.Empty;
- var name = string.Empty;
- var damage = 45;
- var health = 250;
- var armor = 10;
- var match = regex.Match(inputLine);
- type = match.Groups[1].Value;
- name = match.Groups[2].Value;
- if (match.Groups[3].Value != "null")
- {
- damage = int.Parse(match.Groups[3].Value);
- }
- if (match.Groups[4].Value != "null")
- {
- health = int.Parse(match.Groups[4].Value);
- }
- if (match.Groups[5].Value != "null")
- {
- armor = int.Parse(match.Groups[5].Value);
- }
- if (!typesDragons.ContainsKey(type))
- {
- typesDragons.Add(type, new SortedDictionary<string, int[]>());
- }
- if (!typesDragons[type].ContainsKey(name))
- {
- typesDragons[type].Add(name, new int[3]);
- }
- typesDragons[type][name][0] = damage;
- typesDragons[type][name][1] = health;
- typesDragons[type][name][2] = armor;
- }
- foreach (var type in typesDragons)
- {
- var avrDamage = type.Value
- .Select(n => n.Value[0])
- .Average();
- var avrHealth = type.Value
- .Select(n => n.Value[1])
- .Average();
- var avrArmor = type.Value
- .Select(n => n.Value[2])
- .Average();
- Console.WriteLine(
- "{0}::({1:F2}/{2:F2}/{3:F2})",
- type.Key,
- avrDamage,
- avrHealth,
- avrArmor);
- foreach (var dragon in type.Value)
- {
- Console.WriteLine(
- "-{0} -> damage: {1}, health: {2}, armor: {3}",
- dragon.Key,
- dragon.Value[0],
- dragon.Value[1],
- dragon.Value[2]);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement