2- tajriba ishi
Birinchi satrda bitta sonni – so’ralgan sonlardan nechtasi berilgan massivdauchrashini chiqaring. Agar hech biri uchramasa 0 chiqaring.
Misollar
№
|
Kiruvchi ma’lumotlar
|
Chiquvchi ma’lumotlar
|
1
|
5
1 4 6 10 20
4
1
25
10
10
|
3
|
#include
using namespace std;
int a[100];
int binsearch(int x, int l, int r) {
while (r-l > 1) {
int m = (l+r)/2;
if (a[m] > x)
r = m;
else
l = m;
}
if (a[l]==x)
return l;
return -1;
}
int main(){
int n;
cin>>n;
for(int i=1; i<=n; i++){
cin>>a[i];
}
int m;
cin>>m;
int b[m+1];
int cnt = 0;
for(int i=1; i<=m; i++){
cin>>b[i];
int id = binsearch(b[i],1,n+1);
if(id!=-1) cnt++;
}
cout<<"Natija: "<}
Do'stlaringiz bilan baham: |