Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Dictionary___Battle_Manager
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int[]> people = new Dictionary<string, int[]>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "Results")
- {
- break;
- }
- string[] tokens = input.Split(":");
- string command = tokens[0];
- switch (command)
- {
- case "Add":
- string personName = tokens[1];
- int health = int.Parse(tokens[2]);
- int energy = int.Parse(tokens[3]);
- if (!people.ContainsKey(personName))
- {
- people.Add(personName, new int[2] { health, energy });
- }
- else
- {
- people[personName][0] += health;
- }
- break;
- case "Attack":
- string attackerName = tokens[1];
- string defenderName = tokens[2];
- int damage = int.Parse(tokens[3]);
- if (people.ContainsKey(attackerName) && people.ContainsKey(defenderName))
- {
- people[defenderName][0] -= damage;
- if (people[defenderName][0] <= 0)
- {
- people.Remove(defenderName);
- Console.WriteLine($"{defenderName} was disqualified!");
- }
- people[attackerName][1] -= 1;
- if (people[attackerName][1] <= 0)
- {
- people.Remove(attackerName);
- Console.WriteLine($"{attackerName} was disqualified!");
- }
- }
- break;
- case "Delete":
- string username = tokens[1];
- if (username == "All")
- {
- people.Clear();
- }
- if (people.ContainsKey(username))
- {
- people.Remove(username);
- }
- break;
- }
- }
- Console.WriteLine($"People count: {people.Count}");
- people = people
- .OrderByDescending(x => x.Value[0])
- .ThenBy(x => x.Key)
- .ToDictionary(x => x.Key, y => y.Value);
- foreach (var person in people)
- {
- Console.WriteLine($"{person.Key} - {string.Join(" - ", person.Value)}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement