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; }