UVA - 10474 Where is the Marble

xiaoxiao2021-02-28  108

/* 算是水题,难度不大 有个值得注意的小细节是,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; }
转载请注明原文地址: https://www.6miu.com/read-38428.html

最新回复(0)