Skip to content

Instantly share code, notes, and snippets.

@PreSoichiSumi
Created April 26, 2016 08:20
Show Gist options
  • Save PreSoichiSumi/7ede09c8cbf44cbcdc28221026db5bf0 to your computer and use it in GitHub Desktop.
Save PreSoichiSumi/7ede09c8cbf44cbcdc28221026db5bf0 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int A1,A2,B1,B2;
A1=sc.nextInt();
A2=sc.nextInt();
B1=sc.nextInt();
B2=sc.nextInt();
int C=sc.nextInt();
Set<Integer> A=new HashSet<>();
Set<Integer> B =new HashSet<>();
A.add(A1);
A.add(A2);
B.add(B1);
B.add(B2);
Set<Integer> res=new LinkedHashSet<Integer>();
if(A.contains(C) && B.contains(C)){
res.addAll(A);
res.addAll(B);
}else if(A.contains(C)){
res.addAll(B);
}else{
res.addAll(A);
}
List<Integer> list=new ArrayList<>();
list.addAll(res);
Collections.sort(list);
System.out.println(list.size());
for (Integer integer : list) {
System.out.println(integer);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment