UVA-70474Where is the Marble?

来源:互联网 发布:手机贴吧抢二楼软件 编辑:程序博客网 时间:2024/06/08 05:15

Raju and Meena love to play with Marbles. They have got a lot ofmarbles with numbers written on them. At the beginning, Raju wouldplace the marbles one after another in ascending order of the numberswritten on them. Then Meena would ask Raju to find the first marblewith a certain number. She would count 1...2...3. Raju gets one pointfor correct answer, and Meena gets the point if Raju fails. After somefixed number of trials the game ends and the player with maximumpoints wins. Today it’s your chance to play as Raju. Being the smartkid, you’d be taking the favor of a computer. But don’t underestimateMeena, she had written a program to keep track how much time you’retaking 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 beginswith 2 integers: N the number of marbles and Q the number of queries Mina would make. The nextN lines would contain the numbers written on the N marbles. These marble numbers will not comein any particular order. Following Q lines will have Q queries. Be assured, none of the input numbersare greater than 10000 and none of them are negative.Input is terminated by a test case where N = 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 whetheror not the query number is written upon any of the marbles. The two different formats are describedbelow:• ‘x found at y’, if the first marble with number x was found at position y. Positions are numbered1, 2, . . . , N.• ‘x not found’, if the marble with number x is not present.Look at the output for sample input for details.

Sample Input4 1235155 213331230 0

Sample OutputCASE# 1:5 found at 4CASE# 2:2 not found3 found at 3

#include <iostream>#include<cstdio>#include<cstring>#include<string.h>#include<string>#include<stdio.h>#include<algorithm>using namespace std;int main(){    int a[100001];    int n,i;    int m;    int t=1;    int b;    int j;    int f;    while(scanf("%d%d",&m,&n),m!=0&&n!=0)    {        for(i=0;i<m;i++)            scanf("%d",&a[i]);        sort(a,a+m);        printf("CASE# %d:\n",t);        while(n--)        {            scanf("%d",&b);            for(i=0;i<m;i++)            {                f=0;                if(a[i]==b)                {                    f=1;                    printf("%d found at %d\n",b,i+1);                    break;                }            }            if(f==0)                printf("%d not found\n",b);        }        t++;    }    return 0;}


原创粉丝点击