最高身高用结构体解决
输入n名同学的姓名和身高,输出身高最高的同学的姓名和身高。#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
string name, tallest_name;
int height, tallest_height = -1;
for (int i = 0; i < n; i++) {
cin >> name >> height;
if (height > tallest_height) {
tallest_height = height;
tallest_name = name;
}
}
cout << tallest_name << " " << tallest_height << endl;
return 0;
}