#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 10000;
int main()
{
int n, q, x, a[maxn], kase = 0;
while(scanf("%d%d", &n, &q) == 2 && n) {
printf("CASE# %d:\n", ++kase);//格式化输出
for(int i = 0; i < n; i++) scanf("%d", &a[i]);//输入每个大理石上的数字
sort(a, a+n);//对n个大理石进行排序
while(q--) {//循环q个问题
scanf("%d", &x);
int p = lower_bound(a, a+n, x) - a;//用lower_bound()函数查找“大于或者等于x的第一个位置”
if(a[p] == x) printf("%d found at %d\n", x, p+1);
else printf("%d not found\n", x);
}
}
return 0;
}
uva10474 Where is the Marble?
最新推荐文章于 2022-01-18 15:51:31 发布
本文介绍了一个使用C++实现的程序示例,该程序包括读取输入、对整数数组进行排序以及通过二分查找算法寻找特定值的过程。通过对用户提供的数据进行排序和查找操作,展示了C++标准库中sort函数和lower_bound函数的应用。
1013

被折叠的 条评论
为什么被折叠?



