PAT B Zhenti --1004 standings (C ++ version)

1004 standings

 

Read n (> 0) student name, student number, grades, scores were highest output and the lowest score the student's name and student number.

Input formats:

Each test comprises a test input format

第 1 行:正整数 n
第 2 行:第 1 个学生的姓名 学号 成绩
第 3 行:第 2 个学生的姓名 学号 成绩
  ... ... ...
第 n+1 行:第 n 个学生的姓名 学号 成绩

Wherein 姓名and 学号are no more than 10 characters in the string, the result is an integer between 0 and 100, where a set of test cases to ensure that no two are the same student achievement.

Output formats:

For each test case output 2, line 1 is the highest score a student's name and student number, the second line is the lowest score the student's name and student number, there is a space between the strings.

Sample input:

3
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95

Sample output:

Mike CS991301
Joe Math990112

Complete code (C ++) as follows:

#include<iostream>

using namespace std;

//student类
class student{
	public:
		char name[11];
		char xuehao[11];
		int score;
};

//主函数
int main()
{
	int n;
	cin>>n;

//new一个对象
	student* stu = new student[n];

//输入n个学生
	for(int i = 0;i<n;i++)
	{
		cin>>stu[i].name>>stu[i].xuehao>>stu[i].score;
	 } 

	int max=stu[0].score;
	int min=stu[0].score;
	int count1=0,count2=0;

//按成绩进行排序
	for(int i= 1;i<n;i++)
	{
		if(stu[i].score>max)
		{
			max = stu[i].score;
			count1 = i;
		}
		if(stu[i].score<min)
		{
			min = stu[i].score;
			count2 = i;
		}
	}

//输出第一名第二名学生信息
	cout<<stu[count1].name<<" "<<stu[count1].xuehao<<endl;
	cout<<stu[count2].name<<" "<<stu[count2].xuehao<<endl;
	return 0;
}

 

Guess you like

Origin blog.csdn.net/qq_42415326/article/details/94480234