Search II
You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S.
Input
In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers are given.
Output
Print C in a line.
Constraints
Elements in S is sorted in ascending order
n ≤ 100000
q ≤ 500000 ≤ an element in S ≤ 1090 ≤ an element in T ≤ 109
Sample Input 15123453341
Sample Output 13
Sample Input 2312315
Sample Output 20
Sample Input 3511223212
Sample Output 32
代码块
#include<iostream>usingnamespace std;intBinarySearch(int*a,int n,int key){int left =0;int right = n-1;while(left<=right){int mid =(left+right)/2;if(key==a[mid])return1;elseif(key<a[mid])
right = mid-1;else
left = mid+1;}return0;}intmain(void){int i, n, q;
cin>>n;int a[n];for(i=0; i<n; i++)
cin>>a[i];
cin>>q;int key;int sum =0;for(i=0; i<q; i++){
cin>>key;if(BinarySearch(a, n, key))
sum++;}
cout<<sum<<endl;return0;}
题目Search IIYou are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S.InputIn the first line n is given. In the second line, n integers ar