Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace P09.BattleManager
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> healthProfile = new Dictionary<string, int>();
- Dictionary<string, int> energyProfile = new Dictionary<string, int>();
- string line = Console.ReadLine();
- while (line != "Results")
- {
- string[] cmdArgs = line.Split(":");
- string command = cmdArgs[0];
- switch (command)
- {
- case "Add":
- string username = cmdArgs[1];
- int health = int.Parse(cmdArgs[2]);
- int energy = int.Parse(cmdArgs[3]);
- if (!healthProfile.ContainsKey(username))
- {
- healthProfile.Add(username, 0);
- energyProfile.Add(username, energy);
- }
- healthProfile[username] += health;
- break;
- case "Attack":
- string attacker = cmdArgs[1];
- string defender = cmdArgs[2];
- int damage = int.Parse(cmdArgs[3]);
- if (healthProfile.ContainsKey(attacker))
- {
- healthProfile[defender] -= damage;
- if (healthProfile[defender] <= 0)
- {
- healthProfile.Remove(defender);
- energyProfile.Remove(defender);
- Console.WriteLine($"{defender} was disqualified!");
- }
- energyProfile[attacker]--;
- if (energyProfile[attacker] <= 0)
- {
- healthProfile.Remove(attacker);
- energyProfile.Remove(attacker);
- Console.WriteLine($"{attacker} was disqualified!");
- }
- }
- break;
- case "Delete":
- string user = cmdArgs[1];
- if (user == "All")
- {
- healthProfile.Clear();
- energyProfile.Clear();
- }
- else
- {
- if (healthProfile.ContainsKey(user))
- {
- healthProfile.Remove(user);
- energyProfile.Remove(user);
- }
- }
- break;
- default:
- break;
- }
- line = Console.ReadLine();
- }
- Console.WriteLine($"People count: {healthProfile.Keys.Count}");
- foreach (var user in healthProfile.OrderByDescending(u => u.Value).ThenBy(n => n.Key))
- {
- Console.WriteLine($"{user.Key} - {user.Value} - {energyProfile[user.Key]}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement