3- tajriba
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
|
10
-3 -3 -3 -3 4 4 4 6 6 20
4
4
-3
7
6
|
9
|
#include
using namespace std;
int a[100];
int lowerbound(int x, int l, int r) {
while (r-l > 1) {
int m = (l+r)/2;
if (a[m] < x)
l = m;
else
r = m;
}
if (a[r]==x)
return r;
return -1;
}
int upperbound(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 x;
cin>>x;
int id1 = lowerbound(x,1,n+1);
int id2 = upperbound(x,1,n+1);
cout<}
Do'stlaringiz bilan baham: |