1.
#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int a[310], n, k = 0;
cin >> n;
while (n != -99999)
{
a[k ++] = n;
cin >> n;
}
cin >> n;
for (int i = 0; i < k; i ++)
{
if (a[i] == n)
{
cout << i;
return 0;
}
}
cout << -1 << endl;
return 0;
}
2.
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
int a[100];
for (int i = 0; i < 2 * n; i ++)
{
cin >> a[i];
}
sort(a, a + 2 * n);
int ans = a[n - 1];
cout << ans << endl;
}
3.
#include <iostream>
#include <cstdio>
using namespace std;
int BinSearch(int r[], int n, int k)
{
int mid, low = 0, high = n - 1;
while (low <= high)
{
mid = (low + high) / 2;
if (k < r[mid]) high = mid - 1;
else if (k > r[mid]) low = mid + 1;
else return mid + 1;
}
return 0;
}
int main()
{
int n;
cin >> n;
int i, a[100];
for (i = 0; i < n; i ++)
{
cin >> a[i];
}
int k;
cin >> k;
cout << BinSearch(a, n, k) << endl;
}
标签:15,cout,上机,int,cin,mid,++,2023.5,include
From: https://www.cnblogs.com/fghjktgbijn/p/17402823.html