一、题目链接
http://noi.openjudge.cn/ch0109/02/
二、解题思路
三、实施步骤
四、Java程序
import java.util.Scanner;
class Student {
private String name;
private int score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}
public class Main {
public Student topStudent(Student[] students) {
int n = students.length;
int max_pos = 0;
for (int i = 1; i < n; i++) {
if (students[i].getScore() > students[max_pos].getScore()) {
max_pos = i;
}
}
return students[max_pos];
}
public static void main(String[] args) {
Main test = new Main();
Scanner input = new Scanner(System.in);
int N = input.nextInt();
Student[] students = new Student[N];
for (int i = 0; i < N; i++) {
students[i] = new Student();
students[i].setScore(input.nextInt());
students[i].setName(input.next());
}
System.out.print(test.topStudent(students).getName());
}
}