Reads the n-( >) student's name, school, achievement, output the highest score and the lowest score the student's name and student number.
Input formats:
Each test comprises a test input format
第 1 行:正整数 n
第 2 行:第 1 个学生的姓名 学号 成绩
第 3 行:第 2 个学生的姓名 学号 成绩 ... ... ... 第 n+1 行:第 n 个学生的姓名 学号 成绩
Wherein 姓名
and 学号
are no more than 10 characters in the string, the result is an integer between 0 and 100, where a set of test cases to ensure that no two are the same student achievement.
Output formats:
For each test case output 2, line 1 is the highest score a student's name and student number, the second line is the lowest score the student's name and student number, there is a space between the strings.
Sample input:
3
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95
Sample output:
Mike CS991301
Joe Math990112
Ideas:
• definition of the structure using Students container vector dynamic array types stu (n), and the input note define n n, then use;
• definition of the structure of a member ordering function CMP (), sorted using the sort function, resulting in the overall structure stu.score as sequential ordering.
. 1 #include <the iostream> 2 #include < String > . 3 #include <Vector> . 4 #include <algorithm> . 5 the using namespace STD; . 6 struct Students. . 7 { . 8 String name; . 9 String ID; 10 int Score; . 11 }; 12 is // structure defines two types of Students, which comparison member Score 13 is BOOL CMP (Students a, B Students) { 14 return a.score < b.score; 15 } 16 int main() { 17 int n; 18 cin>>n; 19 vector<Students>stu(n); 20 for (int i = 0; i < n; i++) { 21 cin >> stu[i].name >> stu[i].id >> stu[i].score; 22 } 23 sort(stu.begin(), stu.begin() + n,cmp); 24 cout << stu[n - 1].name << " " << stu[n - 1].id << endl; 25 cout << stu[0].name << " " << stu[0].id << endl; 26 return 0; 27 }