1004 成績排名

2021-10-05 08:00:43 字數 1212 閱讀 6224

讀入 n(>0)名學生的姓名、學號、成績,分別輸出成績最高和成績最低學生的姓名和學號。

每個測試輸入包含 1 個測試用例,格式為

第 1 行:正整數 n

第 2 行:第 1 個學生的姓名 學號 成績

第 3 行:第 2 個學生的姓名 學號 成績

... ... ...

第 n+1 行:第 n 個學生的姓名 學號 成績

其中姓名學號均為不超過 10 個字元的字串,成績為 0 到 100 之間的乙個整數,這裡保證在一組測試用例中沒有兩個學生的成績是相同的。

對每個測試用例輸出 2 行,第 1 行是成績最高學生的姓名和學號,第 2 行是成績最低學生的姓名和學號,字串間有 1 空格。

3

joe math990112 89

mike cs991301 100

mary ee990830 95

mike cs991301

joe math990112

#include

#include

#include

#include

#include

//#include

//#include

using namespace std;

struct st {

string name;

string num;

int gra;

int main() {

int n;

cin >> n;

st a[1000];

int max = 0, min = 100;

int x, y;

for (int i = 0; i < n; i++) {

cin >> a[i].name >> a[i].num >> a[i].gra;

if (max < a[i].gra) {

max = a[i].gra;

x = i;

if (min > a[i].gra) {

min = a[i].gra;

y = i;

cout << a[x].name << " " << a[x].num << endl;

cout << a[y].name << " " << a[y].num ;

1004成績排名

讀入n名學生的姓名 學號 成績,分別輸出成績最高和成績最低學生的姓名和學號。輸入格式 每個測試輸入包含1個測試用例,格式為 第1行 正整數n 第2行 第1個學生的姓名 學號 成績 第3行 第2個學生的姓名 學號 成績 第n 1行 第n個學生的姓名 學號 成績其中姓名和學號均為不超過10個字元的字串,...

1004 成績排名

讀入n名學生的姓名 學號 成績,分別輸出成績最高和成績最低學生的姓名和學號。輸入格式 每個測試輸入包含1個測試用例,格式為 第1行 正整數n 第2行 第1個學生的姓名 學號 成績 第3行 第2個學生的姓名 學號 成績 第n 1行 第n個學生的姓名 學號 成績其中姓名和學號均為不超過10個字元的字串,...

1004 成績排名

這個相對來說比較簡單,但是沒能一次執行成功。要記得 結構體存資料取位址 include include include pragma warning disable 4996 int main struct student x scanf d n x struct student malloc n ...