Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them. At the beginning, Raju would place the marbles one after another in ascending order of the numbers written on them. Then Meena would ask Raju to find the first marble with a certain number. She would 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: N the number of marbles and Q the number of queries Mina would make. The next N lines would contain the numbers written on the N marbles. These marble numbers will not come in any particular order. Following Q lines will have Q queries. Be assured, none of the input numbers are 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 whether or not the query number is written upon any of the marbles. The two different formats are described below:

• ‘x found at y’, if the first marble with number x was found at position y. Positions are numbered 1,2,...,N.

• ‘x not found’, if the marble with number x is not present.

Look at the output for sample input for details.

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

HINT

  比较简单的C++入门,就是先排序然后查找输出结果。

Accepted

#include<algorithm>
#include <iostream>
using namespace std; int main()
{
int m, n;
int num = 0;
while (cin>>m>>n&&m&&n)
{
int arr[10001];
for (int i = 0;i < m;i++)cin >> arr[i];
sort(arr, arr + m);
cout << "CASE# " << ++num << ":"<<endl;
for (int i = 0;i < n;i++)
{
int p, q;
cin >> p;
q = lower_bound(arr,arr+m,p) - arr;
if (arr[q] == p&&q!=m)cout << p << " found at " << q+1 << endl;
else cout << p << " not found" << endl;
}
}
}

Where is the Marble UVA - 10474的更多相关文章

  1. 大理石在哪儿 (Where is the Marble?,UVa 10474)

    题目描述:算法竞赛入门经典例题5-1 #include <iostream> #include <algorithm> using namespace std; ; int m ...

  2. UVA.10474 Where is the Marble ( 排序 二分查找 )

    UVA.10474 Where is the Marble ( 排序 二分查找 ) 题意分析 大水题一道.排序好找到第一个目标数字的位置,返回其下标即可.暴力可过,强行写了一发BS,发现错误百出.应了 ...

  3. 【UVA - 10474 】Where is the Marble?(排序)

    Where is the Marble? Descriptions: Raju and Meena love to play with Marbles. They have got a lot of ...

  4. 大理石在哪?(Where is the Marble?,UVa 10474)

    参考:ACM紫书 第五章 P108 [排序与检索] 下面的代码中有些 提示性输出,想Ac 需删除提示性输出语句,读者自行修改. #include <cstdio> #include < ...

  5. UVa 10474 Where is the Marble

    题意:给出一列数,先排序,再查找学习了sort函数,lower_bound函数sort:可以给任意对象排序(包括自己定义的)(前提是定义好了‘<’运算符)lower_bound:查找大于或者等于 ...

  6. uva 10474 Where is the Marble? 计数排序

    题目给出一系列数字,然后问哪个数字是从小到大排在第几的,重复出现算第一个. 数据范围为10000,不大,完全可以暴力,sort不会超时. 但是由于以前做比赛时也遇到这种题目,没注意看数据范围,然后暴力 ...

  7. UVA 10474 - Where is the Marble?--vector

    https://vjudge.net/problem/UVA-10474 https://blog.csdn.net/xiyaozhe/article/details/81081344 简单用法 so ...

  8. 大理石在哪儿(Where is the Marble?,Uva 10474)

    现有N个大理石,每个大理石上写了一个非负整数.首先把各数从小到大排序,然后回 答Q个问题.每个问题问是否有一个大理石写着某个整数x,如果是,还要回答哪个大理石上 写着x.排序后的大理石从左到右编号为1 ...

  9. uva 10474 Where is the Marble?(简单题)

    我非常奇怪为什么要把它归类到回溯上,明明就是简单排序,查找就OK了.wa了两次,我还非常不解的怀疑了为什么会 wa,原来是我居然把要找的数字也排序了,当时仅仅是想着能快一点查找.所以就给他排序了,没考 ...

随机推荐

  1. 1.3 PHP+MYSQL+APACHE配置(序)

    本节对服务器端web服务进行配置.事实上,对于配置这个环境(WAMP)网上还是有很多教程的,大家可以通过网上的教程完成配置,也不必拘泥于本文.甚至网上有免费的服务器端软件可以选择,比如著名的phpst ...

  2. 一文读懂clickhouse集群监控

    更多精彩内容,请关注微信公众号:后端技术小屋 一文读懂clickhouse集群监控 常言道,兵马未至,粮草先行,在clickhouse上生产环境之前,我们就得制定好相关的监控方案,包括metric采集 ...

  3. PHP代码审计_用==与===的区别

    目录 背景介绍 如何审计 绕过案例1 绕过案例2 背景介绍 比较==与===的差别 == 是等于符号,=== 是恒等于符号,两个符号的功能都是用来比较两个变量是否相等的,只不过两个符号的比较维度不一样 ...

  4. 漏洞复现-CVE-2014-3120-ElasticSearch 命令执行漏洞

        0x00 实验环境 攻击机:Win 10 靶机也可作为攻击机:Ubuntu18 (docker搭建的vulhub靶场) 0x01 影响版本 < ElasticSearch 1.2的版本 ...

  5. 比较String 字符串的字节大小

    package com.ittx.edi.erp;import java.io.File;import java.io.FileWriter;import java.io.IOException;pu ...

  6. apicloud打包的ios证书的获取方法

    apicloud云编译的时候,需要测试证书或者正式证书进行编译. 那么这个证书是怎么来的呢?通过什么渠道可以获取呢? 这里我介绍下使用香蕉云编这个在线工具来生成: 1.登录香蕉云编,生成证书的csr文 ...

  7. c++ 11 是如何简化你的数据库访问接口的

    之前写过一篇文章专门分析了 c++ 模板编译过程中报的一个错误:<fatal error C1045: 编译器限制 : 链接规范嵌套太深 >,其中涉及到了 qtl -- 一个使用 c++ ...

  8. Hi3559AV100 NNIE开发(3)RuyiStudio软件 .wk文件生成过程-mobilefacenet.cfg的参数配置

    之后随笔将更多笔墨着重于NNIE开发系列,下文是关于Hi3559AV100 NNIE开发(3)RuyiStudio软件 .wk文件生成过程-mobilefacenet.cfg的参数配置,目前项目需要对 ...

  9. Python3+pygame实现的flappy bird游戏,代码完整,还有音乐

    之前一直在手机上玩flappy bird游戏,闲暇时间就编写了一个 是采用python3+pygame模块制作而成的,运行效果非常流畅,会让你大吃一惊哦哈哈 一.运行效果展示 下载游戏之后,注意在自己 ...

  10. JS逆向-抠代码的第一天【手把手学会抠代码】

    首先声明,本人经过无数次摸爬滚打及翻阅各类资料,理论知识极其丰富,但是抠代码怎么都抠不会. 无奈之下,只能承认:这个活,需要熟练度. 本文仅对部分参数进行解析,有需要调用,请自行根据现实情况调整. 第 ...