用普通数组模拟的,输入八个数,就从a[8]-a[15]输入,然后比较a8,a9得出a4,a4a5->a2,依此类推的方法为什么只能过一个
#include <iostream>
using namespace std;
struct Country {
int id; // 国家序号
int score; // 国家成绩
};
int main() {
int n;
cin >> n;
Country countries[n];
for (int i = 0; i < n; i++) {
cin >> countries[i].score;
countries[i].id = i + 1;
}
while (n > 2) {
for (int i = 0; i < n - 1; i += 2) {
if (countries[i].score < countries[i + 1].score) {
countries[i / 2].score = countries[i + 1].score;
countries[i / 2].id = countries[i + 1].id;
} else {
countries[(i + 1) / 2].score = countries[i].score;
countries[(i + 1) / 2].id = countries[i].id;
}
}
n /= 2;
}
cout << countries[0].id << endl;
return 0;
}