#39882: chatgpt 也可以!!


tanghao08152@gmail.com (ttang)

學校 : 康橋雙語學校
編號 : 256363
來源 : [59.120.140.251]
最後登入時間 :
2024-10-11 19:14:23
m931. 1. 遊戲選角 -- 2024年1月APCS | From: [59.120.140.251] | 發表日期 : 2024-04-08 18:46

#include <iostream>
#include <vector>
#include <algorithm>

struct Character {
    int attack;
    int defense;
    int power;

    Character(int atk, int def) : attack(atk), defense(def) {
        power = attack * attack + defense * defense;
    }
};

bool comparePower(const Character &a, const Character &b) {
    return a.power > b.power;
}

int main() {
    int n;
    std::cin >> n;

    std::vector<Character> characters;
    for (int i = 0; i < n; ++i) {
        int attack, defense;
        std::cin >> attack >> defense;
        characters.emplace_back(attack, defense);
    }

    std::sort(characters.begin(), characters.end(), comparePower);

    std::cout << characters[1].attack << " " << characters[1].defense << std::endl;

    return 0;
}

 
ZeroJudge Forum