Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:这道题输出中间一个?

Posted by wskiwwwx at 2010-01-28 15:37:23 on Problem 2388
In Reply To:这道题输出中间一个? Posted by:wskiwwwx at 2010-01-28 15:07:44
>  这道题是输出中间一个?还是?有重复的数字怎么处理?


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

public class Main {

	private static int[] cows;
	private static int len = 0;// 实际长度

	public static void add(int number) {
		if (len == 0)
			cows[len++] = number;
		else {
			cows[len++] = number;
			for (int i = 0; i < len - 1; ++i) {
				if (cows[i] > cows[i + 1]) {
					int tmp = cows[i + 1];
					cows[i + 1] = cows[i];
					cows[i] = tmp;
				}
			}
		}
	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		// Arrays.fill(cows, 0);
		//        
		// len = 0;

		int sum = sc.nextInt();
		cows = new int[sum];
		Arrays.fill(cows, 0);
		len = 0;

		for (int i = 0; i < sum; ++i) {
			int num = sc.nextInt();
			add(num);
			// cows[i] = num;
		}

		// for (int i = 0; i < len; ++i) {
		// System.out.print(cows[i] + " ");
		// }
		//
		// // Arrays.sort(cows);
		// System.out.println(len);
		System.out.println(cows[(sum / 2)]);
	}

}
为什么wa?

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator