1004 成绩排名

水题。
忘了结构体类型变量之间可以直接赋值。惭愧。

#include"iostream"
#include"algorithm"
using namespace std;

struct Student {
    string name,id;
    int score;
};

int main() {
    int n;
    cin>>n;
    Student maxStu,minStu,temp;
    maxStu.score = -1;
    minStu.score = 101;
    for(int i = 0; i < n; ++i) {
        cin>>temp.name>>temp.id>>temp.score;
        if(maxStu.score  < temp.score) maxStu = temp;
        if(minStu.score > temp.score) minStu = temp;
    }
    cout<<maxStu.name<<" "<<maxStu.id<<endl;
    cout<<minStu.name<<" "<<minStu.id<<endl;
    return 0;
}

 

posted @ 2020-02-15 17:57  tangq123  阅读(109)  评论(0编辑  收藏  举报