第三个VS测试没问题的,但在PTA上面就一直段错误。先欠着。。。
#include <iostream> #include <algorithm> using namespace std; struct list { char name[11]; char snumber[11]; int score; }; bool compareab(list a, list b); int main() { list a[10001]; int n; cin >> n; int i = 0; while (i<n) { cin >> a[i].name >> a[i].snumber >> a[i].score; ++i; } sort(a, a + i, compareab); cout << a[0].name << " " << a[0].snumber << endl; cout << a[n-1].name << " " << a[n-1].snumber << endl; return 0; } bool compareab(list a, list b) { return a.score > b.score; }