Advertisement
plamen27

army agon

Dec 17th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. // Решение с Array (ако трябваше да ползваш много място просто правиш масив с много значения - примерно new int[1000] )
  10. Dictionary<string, SortedDictionary<string, int[]>> dict = new Dictionary<string, SortedDictionary<string, int[]>>();
  11. int num = int.Parse(Console.ReadLine());
  12.  
  13. for (int i = 0; i < num; i++)
  14. {
  15. string[] input = Console.ReadLine().Split(' ');
  16. string team = input[0];
  17. string name = input[1];
  18. int damage = (input[2] == "null") ? 45 : int.Parse(input[2]);
  19. int health = (input[3] == "null") ? 250 : int.Parse(input[3]);
  20. int armor = (input[4] == "null") ? 10 : int.Parse(input[4]);
  21. if (!dict.ContainsKey(team))
  22. { dict.Add(team, new SortedDictionary<string, int[]>()); }
  23. if (!dict[team].ContainsKey(name))
  24. { dict[team].Add(name, new int[3]); }
  25. // няма нужда от предварително почистване като с List
  26. dict[team][name][0] = damage;
  27. dict[team][name][1] = health;
  28. dict[team][name][2] = armor;
  29. }
  30. foreach (KeyValuePair<string, SortedDictionary<string, int[]>> team in dict)
  31. {
  32. double damageSum = 0, healthSum = 0, armorSum = 0;
  33. Console.Write("{0}::", team.Key);
  34. foreach (KeyValuePair<string, int[]> teamData in team.Value)
  35. {
  36. damageSum += teamData.Value.ElementAt(0);
  37. healthSum += teamData.Value.ElementAt(1); ;
  38. armorSum += teamData.Value.ElementAt(2); ;
  39. }
  40. Console.WriteLine("({0:F2}/{1:F2}/{2:F2})", damageSum / team.Value.Count(), healthSum / team.Value.Count(), armorSum / team.Value.Count());
  41. foreach (KeyValuePair<string, int[]> teamData in team.Value)
  42. {
  43. Console.WriteLine("-{0} -> damage: {1}, health: {2}, armor: {3}", teamData.Key, teamData.Value.ElementAt(0), teamData.Value.ElementAt(1), teamData.Value.ElementAt(2));
  44. }
  45. }
  46. } // end lines
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement