-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommonElements.java
55 lines (43 loc) · 1.07 KB
/
CommonElements.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/******************************************************************************
print unique elements of three array and display elements (three sorted arrays).
Input:
1 5 10 20 40 80
6 7 20 80 100
3 4 15 20 30 70 80 120
Output: 20 80
Input:
1 5 5
3 4 5 5 10
5 5 10 20
Output: 5 5
*******************************************************************************/
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
String[] s=x.nextLine().split(" ");
int[] a=new int[s.length];
int n=0;
for(String i: s) a[n++]=Integer.parseInt(i);
s=x.nextLine().split(" ");
int[] b=new int[s.length];
n=0;
for(String i: s) b[n++]=Integer.parseInt(i);
s=x.nextLine().split(" ");
n=0;
int[] c=new int[s.length];
for(String i:s) c[n++]=Integer.parseInt(i);
int i=0,j=0,k=0;
while(i<a.length && j<b.length && k<c.length){
if(a[i]==b[j] && b[j]==c[k]){
System.out.print(a[i]+" ");
i++;
j++;
k++;
}else if(a[i]<b[j]) i++;
else if(b[j]<c[k]) j++;
else k++;
}
}
}