Raju and Meena love to play with marbles. they have got a lot of marbles with numbers written on them. at the beginning, Raju wowould place the marbles one after another in ascending order of the numbers written on them. then Meena wocould ask Raju to find the first marble with a certain number. she wocould count 1... 2... 3. raju gets one point for correct answer, and Meena gets the point if Raju fails. after some fixed number of trials the game ends and the player with maximum points wins. today it's your chance to play as Raju. being the smart kid, you 'd be taking the favor of a computer. but don't underestimate Meena, she had written a program to keep track how much time you're taking to give all the answers. so now you have to write a program, which will help you in your role as Raju.
Input
There can be multiple test cases. Total no of test cases is less than 65. Each test case consists begins with 2 integers:NThe number of marbles andQThe number of queries Mina wocould make. The nextNLines wocould contain the numbers written onNMarbles. These marble numbers will not come in any special order. FollowingQLines will haveQQueries. Be assured, none of the input numbers are greater than 10000 and none of them are negative.
Input is terminated by a test case whereN= 0 andQ= 0.
Output
For each test case output the serial number of the case.
For each of the queries, print one line of output. the format of this line will depend upon whether or not the query number is written upon any of the marbles. the two different formats are described below:
- `XFoundY', If the first marble with numberXWas found at positionY. Positions are numbered 1, 2 ,...,N.
- `XNot found', If the marble with numberXIs not present.
Look at the output for sample input for details.
Sample Input
4 1235155 213331230 0
Sample output
CASE# 1:5 found at 4CASE# 2:2 not found3 found at 3
Here we mainly use sort and lower_bound.
# Include <cstdio> # include <string> # include <cmath> # include <queue> # include <vector> # include <sstream> # include <cstring> # include <stdlib. h >#include <iostream >#include <algorithm> using namespace STD; const int maxn = 10000 + 50; int main () {int stone_num; // Number of stones int question_num; // number of questions int case_num = 0; // Number of cases int stone [maxn]; // records the int answer_location of the stone array; // The Position of the stone int question_stone; // while (scanf ("% d", & stone_num, & question_num) = 2 & stone_num & question_num) {for (INT I = 0; I <stone_num; I ++) scanf ("% d", & stone [I]); sort (stone, stone + stone_num ); printf ("case # % d: \ n", ++ case_num); While (question_num --) {scanf ("% d", & question_stone ); int answer_location = lower_bound (stone, stone + stone_num, question_stone)-stone; // lower_bound is used to find "the first location greater than or equal to the number to be queried" If (stone [answer_location] = question_stone) printf ("% d found at % d \ n", question_stone, answer_location + 1); else printf ("% d not found \ n", question_stone );}} return 0 ;}