输入包含两行,第一行包含一个正整数n(1 ≤ n ≤ 1000),表示第二行序列中数字的个数;第二行包含n个整数(范围1~5000),用空格分隔。
输出为一行,按照输入的顺序输出去重之后的数字,用空格分隔。
5 10 12 93 12 75
10 12 93 75
import java.util.LinkedHashSet; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] nums = new int[n]; LinkedHashSet<Integer> drop = new LinkedHashSet<Integer>(); for (int i = 0; i < n; i++) { nums[i] = in.nextInt(); } for (int a : nums) { drop.add(a); } for (Integer b : drop) { System.out.print(b + " "); } } }
import java.util.Scanner; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Arrays; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { // 注意 while 处理多个 case int a = in.nextInt(); LinkedHashSet<Integer> set = new LinkedHashSet<>(); for(int i =0;i<a;i++) { set.add(in.nextInt()); } Iterator<Integer> iterator = set.iterator(); while(iterator.hasNext()) { System.out.print(iterator.next()+" "); } } } }
import java.util.ArrayList; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String nums = sc.nextLine(); String s = sc.nextLine(); ArrayList<Integer> list=new ArrayList<>(); String[] split = s.split(" "); for (int i = 0; i < split.length; i++) { int num = Integer.parseInt(split[i]); if (!list.contains(num)){ list.add(num); } } for (Integer i : list) { System.out.print(i+" "); } } }
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int a=in.nextInt(); ArrayList<Integer> arrA=new ArrayList<Integer>(); ArrayList<Integer> arrB=new ArrayList<Integer>(); for(int i=0;i<a;i++){ arrA.add(in.nextInt()); } for(int i=0;i<arrA.size();i++){ if(!arrB.contains(arrA.get(i))){ arrB.add(arrA.get(i)); } } for(int i=0;i<arrB.size();i++){ System.out.print(arrB.get(i)+" "); } } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int all=sc.nextInt(); int[] arr=new int[all]; for(int i=0;i<all;i++) arr[i]=sc.nextInt(); List<Integer> list=new ArrayList<>(); for(int i:arr){ if(!list.contains(i)) list.add(i); } for(int i:list) System.out.printf("%d ",i); } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; LinkedHashSet <Integer> quchong = new LinkedHashSet<Integer>(); for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } for (int a : arr) { quchong.add(a); } for (Integer b : quchong) { System.out.print(b + " "); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ int n = scanner.nextInt(); //要输入数据的集合 List<Integer> inputList = new ArrayList<>(); //去重后的集合 List<Integer> toDeleteRepeatNumList = new ArrayList<>(); //输入 for(int i = 0;i < n;i++){ inputList.add(scanner.nextInt()); } //判断重复,有的话就不输入到新集合下 for(int j = 0;j < inputList.size();j++){ if(!toDeleteRepeatNumList.contains(inputList.get(j))){ toDeleteRepeatNumList.add(inputList.get(j)); } } //输出 for(int k = 0;k< toDeleteRepeatNumList.size();k++){ System.out.print(toDeleteRepeatNumList.get(k) + " "); } } } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); ArrayList<Integer> list=new ArrayList<>(); for(int i=0;i<n;i++){ list.add(sc.nextInt()); } ArrayList<Integer> list_=new ArrayList<>(); for(int x : list ){ if(!list_.contains(x)){ list_.add(x); } } list_.forEach(e->System.out.print(e+" ")); } } }
import java.util.LinkedHashSet;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = Integer.parseInt(scan.nextLine());
String line = scan.nextLine();
String[] str = line.split("[ ]");
LinkedHashSet<object> temp = new LinkedHashSet<>();
for(int i=0;i<str.length;i++) {
temp.add(str[i]);
}
for(Object x:temp) {
System.out.print(x+" ");
}
}</object>
}
import java.util.*; import java.util.stream.Collectors; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); Set<String> set = new LinkedHashSet<>(); for (int i = 0; i < n; i++) { set.add(Integer.toString(sc.nextInt())); } String res = set.stream().collect(Collectors.joining(" ")); System.out.println(res); } } }
import java.util.*; public class Main { public static void main(String [] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()) { int n=sc.nextInt(); int [] arr=new int[n]; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); } LinkedHashSet<Integer> set=new LinkedHashSet<>(); for(int i=0;i<n;i++) { set.add(arr[i]); } for(int num:set) { System.out.print(num+" "); } } } }