Created
December 22, 2015 02:10
-
-
Save peter279k/e9b725e8d10e9e326622 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class main{ | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
while(input.hasNext()) { | |
String str = ""; | |
int number = input.nextInt(); | |
int []nums = new int[number]; | |
for(int i=0;i<number;i++) { | |
nums[i] = input.nextInt(); | |
} | |
Arrays.sort(nums); | |
int count = 0; | |
if(number % 2 == 0) { | |
str += String.valueOf(nums[(number + 1) / 2 - 1]) + " "; | |
count = 2; | |
for(int i=0;i<nums.length;i++) { | |
if(i == (number + 1) / 2 - 1 || i == (number + 1) / 2) | |
continue; | |
if(nums[i] == nums[(number + 1) / 2] || nums[i] == nums[(number + 1) / 2 - 1]) | |
count += 1; | |
} | |
str += String.valueOf(count) + " "; | |
str += String.valueOf(nums[(number + 1) / 2] - nums[(number + 1) / 2 - 1] + 1) + "\r\n"; | |
System.out.print(str); | |
} | |
else { | |
str += String.valueOf(nums[(number - 1) / 2]) + " "; | |
count = 1; | |
for(int i=0;i<nums.length;i++) { | |
if(i == (number - 1) / 2) | |
continue; | |
if(nums[i] == nums[(number - 1) / 2]) | |
count += 1; | |
} | |
str += String.valueOf(count) + " "; | |
str += "1" + "\r\n"; | |
System.out.print(str); | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment