题目链接:https://vjudge.net/problem/UVA-10474
题目比较简单就不翻译了,主要实现排序和搜索:
1)存数组 2) sort 3) lower_bound 4)验证
奉AC代码:(注意 lower_bound 的使用)
#include "stdafx.h"
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;
int main()
{
int cp = 0, n, q, x, p;
while (cin >> n >> q && n) {
int a[11111] = { 0 };//"none of the input numbers are greater than 10000"
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
printf("CASE# %d:\n", ++cp);
while (q--) {
cin >> x;
p = lower_bound(a,a+n,x) - a;//be index.
if (a[p] == x) printf("%d found at %d\n", x, p+1);
else printf("%d not found\n", x);
}
}
return 0;
}