https://pintia.cn/problem-sets/994805260223102976/problems
#include <bits/stdc++.h>
using namespace std;
using gg = long long;
struct Student {
string name, number; //出错,写成了char
gg score;
Student(gg s = 0) : score(s) {}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
gg n;
cin >> n;
Student Max(-1), Min(101), temp; // Max初始成绩为-1,Min初试成绩为101
for (gg i = 0; i < n; ++i) {
cin >> temp.name >> temp.number >> temp.score;
if (Max.score < temp.score)
Max = temp;
if (Min.score > temp.score)
Min = temp;
}
cout << Max.name << " " << Max.number << "\n" << Min.name << " " << Min.number;
return 0;
}
#include<iostream> using namespace std ; struct Student{ string name , id ; int score; Student(int s = 0): score(s){} }; int main() { int n ; cin >> n; Student max(-1) , min(101) , temp ; for(int i = 0 ;i < n ; i++) //若为for(int i = 1 ;i < n ; i++) 漏掉了一个例子,经常出此错 { cin >> temp.name >> temp.id >> temp.score ; if( temp.score > max.score ) max = temp ; if(temp.score < min.score) min = temp ; } cout << max.name << ' ' << max.id << endl; cout << min.name << ' ' << min.id; return 0; }