-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindingSameKeys.cpp
49 lines (39 loc) · 1014 Bytes
/
FindingSameKeys.cpp
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
//2012004236_Guyeol\Jeong
#include <stdio.h>
#include <stdlib.h>
#define BIGGER(a,b) ((a)>(b)?(a):(b))
int max_key(int *a, int n){
int max=a[0], i;
for(i=0;i<n;i++){
if(a[i]>max)
max=a[i];
}
return max;
}
int main() {
int n,m,i,max;
int *keyset_a, *keyset_b;
int *count_arr, num_of_same_key=0;
scanf("%d %d",&n,&m);
keyset_a=(int*)malloc(sizeof(int)*n);
keyset_b=(int*)malloc(sizeof(int)*m);
for(i=0;i<n;i++)
scanf("%d",&keyset_a[i]);
for(i=0;i<m;i++)
scanf("%d",&keyset_b[i]);
max=BIGGER(max_key(keyset_a,n),max_key(keyset_b,m));
count_arr=(int*)malloc(sizeof(int)*(max+1));
for(i=0;i<=max;i++)
count_arr[i]=0;
for(i=0;i<n;i++)
count_arr[keyset_a[i]]++;
for(i=0;i<m;i++){
if(count_arr[keyset_b[i]]>0)
num_of_same_key++;
}
printf("%d\n",num_of_same_key);
free(count_arr);
free(keyset_b);
free(keyset_a);
return 0;
}