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. nyoj_176_队花的烦恼二_201404262008

    队花的烦恼二 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 ACM队队花C小+最近在X大OJ上做题,竟发现了一道做不出来的…水题!她快郁闷死了……也许是最近状态不太 ...

  2. 【electron系列之一】创建右下角通知栏小图标

    electron 用Tray对象来实现右下角通知栏小图标 一.先引入app, BrowserWindow来实现浏览器功能,接着引入Tray, Menu来实现右下角 二. new Tray('./pag ...

  3. WCF的Binding模型之四:信道工厂(Channel Factory)

    由于信道管理器在客户端和服务端所起的不同作用,分为信道监听器和信道工厂.和服务端的信道监听其相比,处于客户端的信道工厂显得简单.从名称就可以看得出来,信道工厂的作用就是单纯的创建用于消息发送的信道.我 ...

  4. [52ABP系列] - 001、SPA免费项目模版搭建教程

    前言 这个项目是基于 ABP ASPNetCore 免费版,整合 NG-Alian 和 NG-Zorro 的项目,所以比较适合熟悉 ABP 和 Angular2+ 的开发人员, 如果你是新手,学习的话 ...

  5. SAP ABAP 的经常使用debug方式

    SAP ABAP 的经常使用debug方式: 1. 直接在程序中设断点 在se38里面打上breakpoint,程序执行到该处即进入debug模式 2.background Job的debug 进入S ...

  6. [Java] 实验5參考代码

    实验4月3日晚截止,实验截止后将在此给出完整的參考代码. 1. 怎样使用以下的代码模板: 1.1 在eclipse中创建相应名称的类     1.2 将代码拷贝到类文件中 1.3 在//todo凝视中 ...

  7. 打开与关闭Linux防火墙

    1) 重启后生效 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后失效 开启: service iptables sta ...

  8. 工作总结 default Console.WriteLine(default(Guid));

    泛型代码中的默认关键字 在泛型类和泛型方法中产生的一个问题是,在预先未知以下情况时,如何将默认值分配给参数化类型 T: T 是引用类型还是值类型. 如果 T 为值类型,则它是数值还是结构. 给定参数化 ...

  9. [转] Ubuntu/Linux Mint/Debian 安装 Java 8

    本PPA由webupd8制作,支持Ubuntu .04以及对应的Linux Mint版本,Oracle Java 8包提供JDK8 和 JRE8. sudo add-apt-repository pp ...

  10. HDU 1023 Catalan数+高精度

    链接:HDU 1023 /**************************************** * author : Grant Yuan * time : 2014/10/19 15:5 ...