题目描述
给一堆石头排序,找到问题所问的数字,若存在则输出第几块石头(从1开始),若不存在则说not found。
Sample Input
4 1
2
3
5
1
5
5 2
1
3
3
3
1
2
3
0 0
Sample Output
CASE# 1:
5 found at 4
CASE# 2:
2 not found
3 found at 3
//
// Created by yoyoOvQ on 2021/2/3.
//
#include <iostream>
#include <fstream>
#include <algorithm>
const int maxn = 10005;
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
ifstream cin("UVa/in/in-10474.txt");
ofstream cout("UVa/out/out-10474.txt");
#endif
int N,Q,count = 0;
while (cin >> N >> Q && N && Q){
cout << "CASE# " << ++count << ":" << endl;
int a[maxn];
for (int i = 0; i < N; ++i) {
cin >> a[i];
}
sort(a,a+N);
int ans;
int q;
for (int i = 0; i < Q; ++i) {
cin >> q;
ans = lower_bound(a,a+N,q) - a;
if (a[ans] == q)
cout << q << " found at " << ans + 1 << endl;
else
cout << q << " not found" << endl;
}
}
return 0;
}