Uva10474-where is the marble?

Source: Internet
Author: User

Where is the marble?

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
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
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 and
QThe number of queries Mina wocould make. The next
NLines wocould contain the numbers written on
NMarbles. These marble numbers will not come in any special order. Following
QLines 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 and
Q= 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 number
    XWas found at positionY. Positions are numbered
    1, 2 ,...,N.
  • `XNot found', If the marble with number
    XIs 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

The question should be read and sorted and searched. Because each value is non-negative and cannot exceed 10000, it can be sorted in buckets.

# Include <stdio. h>
Void main ()
{Int A [10001], n, Q, I, j, X, sum = 0;
While (scanf ("% d", & N, & Q ))
{If (n + q = 0) break;
++ Sum;
For (I = 1; I <= 10000; I ++) A [I] = 0;
For (I = 1; I <= N; I ++)
{Scanf ("% d", & X );
++ A [x];
}
Printf ("case # % d: \ n", sum );
For (I = 1; I <= Q; I ++)
{Scanf ("% d", & X );
If (A [x]) {n = 1; for (j = 1; j <X; j ++) N + = A [J]; printf ("% d found at % d \ n", X, n );}
Else printf ("% d not found \ n", X );
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.