-
Notifications
You must be signed in to change notification settings - Fork 5
/
Uncommon_Element.java
46 lines (45 loc) · 1.2 KB
/
Uncommon_Element.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
/* Take two set of numbers of two specific lengths A and B.
* Find those numbers of set A which are not in set B.
*
* Input
* ----------------------
* 8 <-------------- Lenght of set A
* 5 <-------------- Length of set B
* 2 5 8 9 4 6 1 7 <-------------- set A
* 1 5 3 8 4 <-------------- set B
*
* Output
* ----------------------
* 2 9 6 7 <-------------- elements of A not in B
*/
import java.util.*;
public class Uncommon_Element {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int[] A = new int[m];
int[] B = new int[n];
for (int i = 0; i < m; i++)
{
A[i]=sc.nextInt();
}
for (int i = 0; i < n; i++) {
B[i] = sc.nextInt();
}
int c=0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < B.length; j++) {
if(A[i]!=B[j])
{
c++;
}
}
if(c == n)
{
System.out.print(A[i]+" ");
}
c = 0;
}
}
}