B1001. 成绩排名

基本思路
- 姓名,name,学号,id,成绩,score,搞一个Student结构体,属性name、id和score
- 搞一个遍历,次数为n,查找属性score最小和最大的结构体,并输出相应的name和id
#include <bits/stdc++.h> using namespace std; struct Student{ string id;// 学号 string name;// 姓名 int score;// 成绩 }max_s, min_s; int main(int argc, char *argv[]) { int n, score; string name, id; cin >> n; // init max_s.score = -1; min_s.score = 101; for(int i = 0; i < n; i++){ cin >> name >> id >> score; if(score > max_s.score){ max_s.name = name; max_s.id = id; max_s.score = score; } if(score < min_s.score){ min_s.name = name; min_s.id = id; min_s.score = score; } } cout << max_s.name << ' ' << max_s.id << endl; cout << min_s.name << ' ' << min_s.id << endl; return 0; }
论读书
睁开眼,书在面前 闭上眼,书在心里
睁开眼,书在面前 闭上眼,书在心里

浙公网安备 33010602011771号