2178チェーンテーブルの整列集合

1392 ワード

Problem Description
集合には重要な特性があります.すなわち、集合内の任意の2つの要素が異なり、集合内の要素が重複しないようにします.重複数を含む無秩序正整数シーケンスをn個与え、チェーンテーブルのノードが数値非降順に配列され、重複要素が含まれていない秩序チェーンテーブルを構築し、その秩序チェーンテーブルを出力します.
Input
テストデータのセットごとに複数のテストデータを入力します.
入力された第1の挙動は正の整数n(1≦n≦100)であり、
第2の挙動n個の正の整数b 1,b 2,...,bn(0 ≤ bi ≤ 230).
Output
テストデータのセットごとに、チェーンテーブルのノード値を降順で出力します.
Sample Input
1
2
2
1 1
6
6 3 5 2 2 3

Sample Output
2
1
2 3 5 6
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while(sc.hasNext())
{
int i = sc.nextInt();
Set a = new TreeSet();
while(i--!=0)
{
a.add(sc.nextInt());
}
//Array.sort(a);
int m=0;
for(int j:a)
{
if(m==0)
System.out.print(j);
else
System.out.print(" "+j);
m++;
}
System.out.printf("
"); //System.out.print(i); } sc.close(); } }