UVA

来源:互联网 发布:仿没内涵网源码模板 编辑:程序博客网 时间:2024/06/07 21:24
/*  算是水题,难度不大    有个值得注意的小细节是,CASE的每个字母都是大写的,而不仅仅是第一个,为此WA一次    值得学习的函数:  sort对vector排序时:sort(v.begin(), v.end())  lower_bound: 查找“大于或等于x的第一个位置”*/#include <iostream>#include <cstdio>#include <algorithm>using namespace std;const int maxn = 1e4;int a[maxn];int main(){int n, q, x, 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);while (q--){scanf("%d", &x);int p = lower_bound(a, a + n, x) - a;if (a[p] == x) printf("%d found at %d\n", x, p + 1);else printf("%d not found\n", x);}}return 0;}

原创粉丝点击