Софтуерно Инженерство
Loading...
+ Нов въпрос
radostin.georgiev avatar radostin.georgiev 8 Точки

03.MOBA Challenger 90/100

Здравейте колеги!

Забих на 90/100, ще може ли съвет за оправяне на грешката.

Благодаря Ви! 

Моето решение: https://pastebin.com/8CZrCBf6

Условие:

 

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

Input

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.

0
PHP Fundamentals
willystyle avatar willystyle 1779 Точки

Втората сортировка не е правилна, трябва да бъде:

uksort($position, function ($key1, $key2) use ($position) {
    $skill1 = $position[$key1];
    $skill2 = $position[$key2];
    if ($skill1 === $skill2) return strcmp($key1, $key2);
    return $skill2 - $skill1;
});

 

0