3. MOBA Challenger - More Exercise: Associative Arrays 90/100
Гърми тест №9. Прегледах решения на колегите из форума, но използвам друга логика за проверяване на общите позиции на играчите и не намерих отговор. Ако може някой да погледне ;)
https://pastebin.com/rXBZ4MmD
Pesho is a pro MOBA player, he is struggling to become а master of the Challenger tier. So he watches carefully the statistics in the tier.
You will receive several input lines in one of the following formats:
"{player} -> {position} -> {skill}"
"{player} vs {player}"
The player and position are strings, the given skill will be an integer number. You need to keep track of every player.
When you receive a player and his position and skill, add him to the player pool, if he isn`t present, else add his position and skill or update his skill, only if the current position skill is lower than the new value.
If you receive "{player} vs {player}" and both players exist in the tier, they duel with the following rules:
Compare their positions, if they got at least one in common, the player with better total skill points wins and the other is demoted from the tier -> remove him. If they have same total skill points, the duel is tie and they both continue in the Season.
If they don`t have positions in common, the duel isn`t happening and both continue in the Season.
You should end your program when you receive the command "Season end". At that point you should print the players, ordered by total skill in desecending order, then ordered by player name in ascending order. Foreach player print their position and skill, ordered desecending by skill, then ordered by position name in ascending order.
Input / Constraints
- The input comes in the form of commands in one of the formats specified above.
- Player and position will always be one word string, containing no whitespaces.
- Skill will be an integer in the range [0, 1000].
- There will be no invalid input lines.
- The programm ends when you receive the command "Season end".
Output
- The output format for each player is:
"{player}: {totalSkill} skill"
"- {position} <::> {skill}"
Examples
Output |
Comments |
|
Pesho -> Adc -> 400 Gosho -> Jungle -> 300 Stamat -> Mid -> 200 Stamat -> Support -> 250 Season end |
Stamat: 450 skill - Support <::> 250 - Mid <::> 200 Pesho: 400 skill - Adc <::> 400 Gosho: 300 skill - Jungle <::> 300 |
We order the players by total skill points descending, then by name. We print every position along its skill ordered descending by skill, then by position name. |
Pesho -> Adc -> 400 Bush -> Tank -> 150 Faker -> Mid -> 200 Faker -> Support -> 250 Faker -> Tank -> 250 Pesho vs Faker Faker vs Bush Faker vs Hide Season end |
Faker: 700 skill - Support <::> 250 - Tank <::> 250 - Mid <::> 200 Pesho: 400 skill - Adc <::> 400 |
Faker and Pesho don`t have common position, so the duel isn`t valid. Faker wins vs Bush /common position: "Tank". Bush is demoted. Hide doesn`t exist so the duel isn`t valid. We print every player left in the tier. |
Варианти има много...кажи по точно за какви колекции имаш на предвид...листове или речници...по принцип най лесно става с .Any( ) , предоставен ни от .Linq, но ако дадеш по точен пример ще измисля нещо по конкретно.
Здравей,
Имам речник Dictionary<string, Dictionary<string, int>>, искам да разбера дали два конкретни ключа от този речник имат поне един общ(еднакъв) ключ от вложения речник :)
Нещо такова измислих, не твърдя, че е перфектното но върши работа... поиграй си с ключовете
Dictionary<string, Dictionary<string, int>> main = new Dictionary<string, Dictionary<string, int>>();
main["1"] = new Dictionary<string, int>();
main["2"] = new Dictionary<string, int>();
main["3"] = new Dictionary<string, int>();
main["1"]["4"] = 2;
main["2"]["4"] = 2;
main["3"]["4"] = 2;
List<string> mainKeys = main.Select(x => x.Key).ToList();
List<string> nestedKeys = main.Values.SelectMany(x => x.Keys).ToList();
bool result = !mainKeys.Except(nestedKeys).Any();