ccf/csp 中间数Java的实现

import java.util.Scanner;

public class ex5_5 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s;
		s = sc.nextLine();
		String[] s_1 = sc.nextLine().split(" ");
		int n = Integer.parseInt(s);
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(s_1[i]);
		}
		int max ;
		int min ;
		int num = 0;
		int sss=0;
		int cc;
		for (int i = 0; i < n; i++) {
			cc = a[i];
			max=0;
			min=0;
			for (int j = 0; j < n; j++) {
				if (a[j] > cc) {
					max++;
				} else if (a[j] < cc) {
					min++;
				}
			}
			if (max == min) {
				sss = a[i];
			}
		}
		if (sss == 0) {
			System.out.println("-1");
		}
		else if(sss!=0) {
			System.out.println(sss);
		}

	}
}

猜你喜欢

转载自blog.csdn.net/qq_40741513/article/details/84978816