-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1196.cpp
More file actions
38 lines (34 loc) · 686 Bytes
/
1196.cpp
File metadata and controls
38 lines (34 loc) · 686 Bytes
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
#include<iostream>
#include<conio.h>
#include<Math.h>
using namespace std;
int binarySearch(int A[], int n, int x) {
int low, high, mid;
low = 0;
high = n-1;
while (low <= high) {
mid = (low + high) / 2;
if (x == A[mid]) return(mid);
else if (x < A[mid]) high = mid-1;
else low = mid + 1;
}
return(-1);
}
int main()
{
int n, a[ 15001 ];
int m, counter = 0;
int b;
cin>>n;
for(int i = 0; i < n; i ++ )
cin>>a[ i ];
cin>>m;
for(int i = 0; i < m; i ++ )
{
cin>>b;
if(binarySearch(a, n, b ) != -1 )
counter ++;
}
cout<<counter<<endl;
return 0;
}