1004. 成绩排名 (20)
求最大最小值,不需要排序
代码如下:
1 #include<iostream> 2 using namespace std; 3 4 int n,max_grade=-1,min_grade=150; 5 int grade_temp; 6 string name1,name2,num1,num2,name_temp,num_temp; 7 int main() 8 { 9 int n; 10 cin>>n; 11 while(n--) 12 { 13 cin>>name_temp>>num_temp>>grade_temp; 14 if(grade_temp>max_grade) 15 { 16 max_grade=grade_temp; 17 name1=name_temp; 18 num1=num_temp; 19 } 20 if(grade_temp<min_grade) 21 { 22 min_grade=grade_temp; 23 name2=name_temp; 24 num2=num_temp; 25 } 26 } 27 cout<<name1<<" "<<num1<<endl; 28 cout<<name2<<" "<<num2<<endl; 29 return 0; 30 }