题目链接:Fighting for HDU
题目的意思就是给你两行数据,分别进行排序。
然后比较。大的得两分,平手一分,输的不得分。
import java.util.Arrays;
import java.util.Scanner;public class Main {private static Scanner scanner;public static void main(String[] args) {scanner = new Scanner(System.in);while (scanner.hasNext()) {int n = scanner.nextInt();if (n == 0) {break;}int a[] = new int[n];int b[] = new int[n];for (int i = 0; i < n; i++) {a[i] = scanner.nextInt();}for (int i = 0; i < n; i++) {b[i] = scanner.nextInt();}// 排序Arrays.sort(a);Arrays.sort(b);int scorea = 0;// a的分数int scoreb = 0;// b的分数for (int i = 0; i < n; i++) {if (a[i] > b[i]) {scorea += 2;} else if (a[i] == b[i]) {scorea += 1;scoreb += 1;} else { // a[i]<b[i];scoreb += 2;}}System.out.println(scorea+" vs "+scoreb);}}
}