1004 成绩排名


import java.util.Arrays;
import java.util.Scanner;

public class Main {
	//方法一
/*	public static void main(String[] args) {
		Scanner inScanner = new Scanner(System.in);	
		int a = inScanner.nextInt();
		String[] student = new String[a];
		inScanner.nextLine();
		String[][] sstudent = new String[a][3];
		for (int i = 0; i < sstudent.length; i++) {
			student[i] = inScanner.nextLine();
			sstudent[i] = student[i].split(" ");
		}
		int max=0,min=0;
		int[] score = new int[a];
		for (int i = 0; i < a; i++) {
			 score[i] = Integer.parseInt(sstudent[i][2]);
		}
		for (int i = 1; i < a; i++) {
			if (score[i]>score[max]) {
				max = i;
			}
			if (score[i]<score[min]) {
				min=i;
			}
			
		}
		System.out.println(sstudent[max][0]+" "+sstudent[max][1]);
		System.out.println(sstudent[min][0]+" "+sstudent[min][1]);

	}*/
	//方法二
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		String[] s	= new String[a];
		int[] score = new int[a];
		in.nextLine();
		for (int i = 0; i < a; i++) {
			Scanner sc = new Scanner(System.in);
			s[i] = sc.nextLine();
			String[] ss=s[i].split(" ");
			score[i] = Integer.parseInt(ss[2]);
		}
		Arrays.sort(score);
		int x = score[0];
		int y = score[a-1];
		for (int i = 0; i < s.length; i++) {
			String[] sss = s[i].split(" ");
			if (Integer.parseInt(sss[2]) == y) {
				System.out.println(sss[0]+" "+sss[1]);
			}
		}
		for (int i = 0; i < s.length; i++) {
			String[] ssss = s[i].split(" ");
			if (Integer.parseInt(ssss[2]) == x) {
				System.out.println(ssss[0]+" "+ssss[1]);
			}
		}
	}
}

上一篇:1004. 最大连续1的个数 III(滑动窗口)


下一篇:contest 1004