13793 - Pokemon Battle Manager 2   

Description

A long long time ago, the sky was dark and gloomy, the ocean was deep and mysterious, and the continent was covered by lava and sandstorm. The mad wild world was dominated by what’s called Pokémon today. It’s a prehistoric era, where the ancient monsters were both arrogant and noble. But it will only last until the human–or whatever the so-called trainer is–comes.

These beautiful creatures are now puppets of a bunch of goddamn ten years old kids. They travel across countries to collect different species of Pokémon for their fetishism, for they are addicted to control, to dominate lives that cannot defy them. Thousands of thousands of innocent Pokémons got caught, imprisoned, and traded as goods.

And yet it’s not the worst. Like any civilization did to the slaves, trainers love to have their Pokémon battle against other trainers’ Pokémon. They compete with each other in their Pokémon battles and consider it glorious if they win, although all they do is sit and watch the poor Pokémons bleeding, burning to death.

Now as a Pokémon battle field manager, you are asked to report the battle process between two given Pokémons. We’ll dig into the details in the following.

In this problem, you are asked to implement 2 functions:

  1. Cure a Pokémon
  2. Simulate a battle

The following is “function.h”. It is guaranteed that the given Pokémon would only be one of the following 5 types: “Geodude”, “Raichu”, “Golbat”, “Magnemite”, and “Exeggutor”, indexed from 0 to 4.

For the function “recover”, you are going to cure a Pokémon, i.e. set Hp to maxHp.

For the function “battle”, you are going to simulate a battle process. Here are the details:

  1. The two Pokémon take turns to move. Pokémons can choose to used attack or special attack on their turns. Pokémon A would move first.
  2. When Pokémon P1 uses attack, it causes damage to the other Pokémon P2, i.e. the Hp of P2 would decrease by the damage. The damage is calculated by the formula below:
    damagmax(× (P1.attac− P2.defense)1)
    After the damage is applied to P2, if P2’s HP is less than 0, P2’s HP should be set to 0.
  3. When Pokémon P1 uses special attack, it causes damage to the other Pokémon P2, i.e. the Hp of P2 would decrease by the damage. The damage is calculated by the formula below:
    damagmax(× (P1.special_attac− P2.special_defense)1)
    After the damage is applied to P2, if P2’s HP is less than 0, P2’s HP should be set to 0.
  4. Pokémon would use attack on their first turn. After that, if they use attack on their previous turn, they would use special attack at this turn; if they use special attack on their previous turn, they would use attack at this turn.
  5. If a Pokémon P1 uses attack to Pokémon P2 on its turns, print the following two sentences: “{P1.name} used {P1.first_move}!”, “{P2.name} now has {P2.Hp} HP.”, each end with a newline character.
  6. If a Pokémon P1 uses special attack to Pokémon P2 on its turns, print the following two sentences: “{P1.name} used {P1.second_move}!”, “{P2.name} now has {P2.Hp} HP.”, each end with a newline character.
  7. Whenever any Pokémon has its Hp equal to 0, the battle ends directly, and you have to report the battle result. In the case that the two of them both got 0 Hp in the end, you have to print “Draw.” ends with a newline character. Otherwise, suppose that the winner is P, the loser is L, print “{P.name} is the winner! {L.name} died in vain…” ends with a newline character, too. After that, print a blank line for mourning one more be gone spirit.
#include <stdio.h>
typedef struct pokemon{
    int id;
    char name[20];
    char first_move[20];
    char second_move[20];
    int attack;
    int special_attack;
    int defense;
    int special_defense;
    int Hp;
    int maxHp;
}Pokemon;
// TODO: recover the Pokémon
void recover(Pokemon *P);
// TODO: simulate and print the process of the battle
void battle(Pokemon *A, Pokemon *B);
 

Input

The first line contains an integer n, representing the number of Pokémons.
The second line contains n integers xi, representing the type of each Pokémon.
The third line contains an integer t, representing the number of operations.
Then, t lines follow, each representing an operation.

Each operation is in the following forms:
1 id:
The id tPokémon recovered.
2 a b:
Please print the battle process of the a th Pokémon and the b th Pokémon.

Output

Execute each operation described in the statement above.
Check the sample output for more details.

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

13793.c

Partial Judge Header

13793.h

Tags




Discuss