Description

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
解题思路:用set容器查看是否含有这个元素,用vector来存所有元素,先排序,再查询。
AC代码:
 #include<bits/stdc++.h>
using namespace std;
int main(){
int n,q,x,y,cnt=;
set<int> se;vector<int> vec;
while(cin>>n>>q&&(n+q)){
se.clear();vec.clear();
while(n--){
cin>>x;
se.insert(x);
vec.push_back(x);
}
cout<<"CASE# "<<cnt++<<':'<<endl;
sort(vec.begin(),vec.end());
while(q--){
cin>>y;
if(!se.count(y))cout<<y<<" not found"<<endl;
else cout<<y<<" found at "<<(lower_bound(vec.begin(),vec.end(),y)-vec.begin()+)<<endl;
}
}
return ;
}
												

H - Where is the Marble?(set+vector)的更多相关文章

  1. C语言中.h和.c文件解析(很精彩)

    C语言中.h和.c文件解析(很精彩)   简单的说其实要理解C文件与头文件(即.h)有什么不同之处,首先需要弄明白编译器的工作过程,一般说来编译器会做以下几个过程: 1.预处理阶段 2.词法与语法分析 ...

  2. 逆向 stdio.h 函数库 fseek 函数(调试版本)

    0x01 fseek 函数 函数原型:int fseek(FILE *stream, long int offset, int whence) 函数功能:设置流 stream 的文件位置为给定的偏移 ...

  3. 逆向 stdio.h 函数库 fopen 函数(调试版本)

    0x01 fopen 函数 函数原型:FILE *fopen(const char *filename, const char *mode) 返回值为 FILE 类型 函数功能:使用给定的模式 mod ...

  4. 蓝桥杯--- 历届试题 大臣的旅费 (DFS & Vector)

    题目提交链接:http://lx.lanqiao.org/problem.page?gpid=T32 问题描述 很久以前,T王国空前繁荣.为了更好地管理国家,王国修建了大量的快速路,用于连接首都和王国 ...

  5. Pet(dfs+vector)

    Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  6. 【PTA 天梯赛训练】词频统计(map+vector)

    请编写程序,对一段英文文本,统计其中所有不同单词的个数,以及词频最大的前10%的单词. 所谓“单词”,是指由不超过80个单词字符组成的连续字符串,但长度超过15的单词将只截取保留前15个单词字符.而合 ...

  7. J - Ananagrams(map+vector)

    Description Most crossword puzzle fans are used to anagrams--groups of words with the same letters i ...

  8. java学习第15天(Linklist Vector)

    根据集合的分类(上一天有说),首先接触的是ArrayList但是和Collection一样,他没有什么特殊的功能,直接跳过,然后是Vector. 一   Vector A:有特有功能 a:添加 pub ...

  9. hdu 4841 圆桌问题(STL vector)

    Problem Description 圆桌上围坐着2n个人.其中n个人是好人,另外n个人是坏人.如果从第一个人开始数数,数到第m个人,则立即处死该人:然后从被处死的人之后开始数数,再将数到的第m个人 ...

随机推荐

  1. Bone Collector II(hdu 2639)

    题意:求01背包的第k最优值 输入:第一行为T,下面是T组数据,每组数据有n,m,k 代表n件物品,m容量,和题目要求的k,下一行是n个物品的价值,再一行是n个物品的体积 输出:T行答案 /* 类似于 ...

  2. codevs1128 导弹拦截

    题目描述 Description 经过11 年的韬光养晦,某国研发出了一种新的导弹拦截系统,凡是与它的距离不超过其工作半径的导弹都能够被它成功拦截.当工作半径为0 时,则能够拦截与它位置恰好相同的导弹 ...

  3. 自定义日志工具LogUtil

    package com.pingyijinren.test; import android.util.Log; /** * Created by Administrator on 2016/5/20 ...

  4. poj_2506_Tiling_201407211555

    Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7509   Accepted: 3672 Descriptio ...

  5. JVM(一):源文件的转变

    JVM(一):源文件的转变 本文讲述一个.java源文件是如何经过javac编译器的一系列操作变为.class文件的. 编译 说到编译,大家都能想到是编译器经过一系列方法将源代码转变为目标机器代码,但 ...

  6. jQuery源代码解析(1)—— jq基础、data缓存系统

    闲话 jquery 的源代码已经到了1.12.0版本号.据官网说1版本号和2版本号若无意外将不再更新,3版本号将做一个架构上大的调整.但预计能兼容IE6-8的.或许这已经是最后的样子了. 我学习jq的 ...

  7. 转:js点击事件在ios中失效的3种解决方案

    ios中不允许将点击事件绑定在document或者body上,如果绑定上的话将会失效.解决方案: 例如:  $(document).on('click', '#generate', function ...

  8. 系统的BIOS与系统安装

    今天偶尔看到个介绍电脑BIOS的与各种本子安装系统的介绍:(记录一下) 网络地址:http://blog.sina.com.cn/s/blog_4a1faae60102dyek.html

  9. 服务器无法处理请求。 ---> 未将对象引用设置到对象的实例

    服务器无法处理请求. ---> 未将对象引用设置到对象的实例. 简短说下我遇到的问题.webservice部署到服务器上后,访问方法报上面的错误,最终原因为改方法需要操作文件夹,加上了相应的权限 ...

  10. Mac SavePanel 保存文件的GUI代码

    // Move the recorded temporary file to a user-specified location (视频文件另存储过程,依据用户选择的路径和文件保存名) NSSaveP ...