← 返回 stripe 的题目列表API Integration: Fetch and Aggregate Data from REST API (PokeAPI practice)
类型:online_judge
Problem: API Integration (Call a REST API and Aggregate Results)
Write a program that calls a third-party REST API and aggregates the results.
Use the public PokeAPI for practice: https://pokeapi.co/.
Task
Given a list of Pokémon names, fetch each Pokémon’s attributes and output:
name
height
weight
all types (in the order returned by the API)
Additionally output:
the name of the heaviest Pokémon among the inputs (tie-break by lexicographically smallest name).
API
For each name p, call:
GET https://pokeapi.co/api/v2/pokemon/{p}
Relevant JSON fields:
name (string)
height (int)
weight (int)
types (array), each has type.name
Input
Line 1: integer n
Next n lines: one Pokémon name per line (lowercase)
Output
First, for each Pokémon in input order, print one line:
<name> <height> <weight> <type1,type2,...>
Finally print:
heaviest: <name>
Constraints
1 <= n <= 50
Names are guaranteed to exist in the API
Handle network failures: retry up to 3 times for each request (non-200 or timeout). If still failing, print error and exit.
Timeout: 2 seconds per request.
Example (illustrative only)
Input
2
pikachu
bulbasaur
Output (illustrative)
pikachu 4 60 electric
bulbasaur 7 69 grass,poison
heaviest: bulbasaur
Example
Input
1
pikachu
Output
(depends on live API) + heaviest line