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_12
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- List<DragonType> ListOfDragonTypes = new List<DragonType>();
- List<DragonType> UpgradedList = new List<DragonType>();
- for (int i = 0; i < n; i++)
- {
- Dragon newDragon = ReadInput();
- bool newDragonType = true;
- for (int j = 0; j < ListOfDragonTypes.Count; j++)
- {
- if (ListOfDragonTypes.ElementAt(j).typeName == newDragon.Type)
- {
- if (CheckDragonEquality(ListOfDragonTypes.ElementAt(j).ListOfDragons, newDragon))
- {
- ListOfDragonTypes.ElementAt(j).ReplaceDragon(ListOfDragonTypes.ElementAt(j), newDragon);
- newDragonType = false;
- break;
- }
- UpgradedList = UpgradingListOfDragonType(ListOfDragonTypes, ListOfDragonTypes.ElementAt(j), newDragon);
- ListOfDragonTypes = UpgradedList;
- newDragonType = false;
- }
- }
- if (newDragonType)
- {
- ListOfDragonTypes = AddNewDragonType(ListOfDragonTypes, newDragon);
- }
- }
- PrintTheResult(ListOfDragonTypes);
- }
- static void PrintTheResult(List<DragonType> finalList)
- {
- foreach (DragonType item in finalList)
- {
- string type = item.typeName;
- double avrDamage = item.SetAvrDamage(item.ListOfDragons);
- double avrHealth = item.SetAvrHealth(item.ListOfDragons);
- double avrArmor = item.SetAvrArmor(item.ListOfDragons);
- Console.WriteLine("{0}::({1:f2}/{2:f2}/{3:f2})", type, avrDamage, avrHealth, avrArmor);
- List<Dragon> currentDragons = item.ListOfDragons;
- currentDragons = SortAlpha(currentDragons);
- foreach (Dragon dragon in currentDragons)
- {
- string dragonName = dragon.Name;
- long dragonDamage = dragon.GetDamage();
- long dragonHealth = dragon.GetHealth();
- long dragonArmor = dragon.GetArmor();
- Console.WriteLine("-{0} -> damage: {1}, health: {2}, armor: {3}", dragonName, dragonDamage, dragonHealth, dragonArmor);
- }
- }
- }
- static List<Dragon> SortAlpha(List<Dragon> listToSort)
- {
- List<Dragon> sortedList = new List<Dragon>();
- sortedList = listToSort.OrderBy(o => o.Name).ToList();
- return sortedList;
- }
- static bool CheckDragonEquality(List<Dragon> ListOfDragons, Dragon dragon2)
- {
- foreach (Dragon item in ListOfDragons)
- {
- if (item.Name == dragon2.Name && item.Type == dragon2.Type)
- {
- return true;
- }
- }
- return false;
- }
- static List<DragonType> UpgradingListOfDragonType(List<DragonType> ListToBeUpgraded, DragonType TypeToBeUpgraded, Dragon newDragon)
- {
- for (int i = 0; i < ListToBeUpgraded.Count; i++)
- {
- if (ListToBeUpgraded.ElementAt(i) == TypeToBeUpgraded)
- {
- ListToBeUpgraded.ElementAt(i).ListOfDragons.Add(newDragon);
- }
- }
- return ListToBeUpgraded;
- }
- static List<DragonType> AddNewDragonType(List<DragonType> listOfDragonTypes, Dragon addedNewDragon)
- {
- DragonType newType = new DragonType(addedNewDragon.Type);
- newType.ListOfDragons.Add(addedNewDragon);
- listOfDragonTypes.Add(newType);
- return listOfDragonTypes;
- }
- static Dragon ReadInput()
- {
- string[] input = Console.ReadLine().Split(' ').ToArray();
- if (input[2] == "null")
- {
- input[2] = "45";
- }
- if (input[3] == "null")
- {
- input[3] = "250";
- }
- if (input[4] == "null")
- {
- input[4] = "10";
- }
- Dragon NewDragon = new Dragon();
- NewDragon.Name = input[1];
- NewDragon.Type = input[0];
- NewDragon.SetDamage(long.Parse(input[2]));
- NewDragon.SetHealth(long.Parse(input[3]));
- NewDragon.SetArmor(long.Parse(input[4]));
- return NewDragon;
- }
- }
- class Dragon
- {
- public string Type { get; set; }
- public string Name { get; set; }
- private long damage = 45;
- private long health = 250;
- private long armor = 10;
- public long GetDamage()
- {
- return damage;
- }
- public long GetHealth()
- {
- return health;
- }
- public long GetArmor()
- {
- return armor;
- }
- public long SetDamage(long Damage)
- {
- this.damage = Damage;
- return Damage;
- }
- public long SetHealth(long Health)
- {
- this.health = Health;
- return Health;
- }
- public long SetArmor(long Armor)
- {
- this.armor = Armor;
- return Armor;
- }
- }
- class DragonType
- {
- public DragonType(string TypeName)
- {
- this.typeName = TypeName;
- }
- public List<Dragon> ListOfDragons = new List<Dragon>();
- public string typeName;
- private double avrDamage;
- private double avrHealth;
- private double avrArmor;
- public double GetAvrDamage()
- {
- return avrArmor;
- }
- public double GetAvrHealth()
- {
- return avrHealth;
- }
- public double GetAvrArmor()
- {
- return avrArmor;
- }
- public double SetAvrDamage(List<Dragon> listOfDragons)
- {
- double sum = 0;
- foreach (Dragon item in listOfDragons)
- {
- sum += item.GetDamage();
- }
- this.avrDamage = sum / listOfDragons.Count;
- return avrDamage;
- }
- public double SetAvrHealth(List<Dragon> listOfDragons)
- {
- double sum = 0;
- foreach (Dragon item in listOfDragons)
- {
- sum += item.GetHealth();
- }
- this.avrHealth = sum / listOfDragons.Count;
- return avrHealth;
- }
- public double SetAvrArmor(List<Dragon> listOfDragons)
- {
- double sum = 0;
- foreach (Dragon item in listOfDragons)
- {
- sum += item.GetArmor();
- }
- this.avrArmor = sum / listOfDragons.Count;
- return avrArmor;
- }
- public DragonType ReplaceDragon(DragonType DragonType, Dragon newDragon)
- {
- for (int i = 0; i < DragonType.ListOfDragons.Count; i++)
- {
- if (DragonType.ListOfDragons.ElementAt(i).Name == newDragon.Name)
- {
- DragonType.ListOfDragons.Remove(DragonType.ListOfDragons.ElementAt(i));
- DragonType.ListOfDragons.Add(newDragon);
- }
- }
- return DragonType;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement