ACM Where is the Marble?
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
/*
Name: Where is the Marble?
Copyright:
Author:
Date: 10/08/17 14:11
Description:
*/ #include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n,q,count,num[],s;
count = ;
while(cin>>n>>q&&n!=||q!=)
{
count++;
cout<<"CASE# "<<count<<":"<<endl;
for(int i = ; i < n;i++)
scanf("%d",&num[i]);
sort(num,num+n); //排序
for(int i = ; i < q; i++)
{
scanf("%d",&s);
int temp = lower_bound(num,num+n,s)-num; //使用lower_bound函数简化代码量
if(num[temp] == s)
cout<<s<<" found at " <<temp+<<endl;
else
cout<<s<<" not found"<<endl;
} } return ;
}
ACM Where is the Marble?的更多相关文章
- zjuoj 3605 Find the Marble
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3605 Find the Marble Time Limit: 2 Seco ...
- HDU 2174 Bridged Marble Rings
题目:Bridged Marble Rings 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2174 题意:如图,要把所有灰色球移动到上圈,每次操作可以转 ...
- SCNU ACM 2016新生赛决赛 解题报告
新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...
- SCNU ACM 2016新生赛初赛 解题报告
新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...
- acm结束了
最后一场比赛打完了.之前为了记录一些题目,开了这个博客,现在结束了acm,这个博客之后也不再更新了. 大家继续加油!
- 关于ACM的总结
看了不少大神的退役帖,今天终于要本弱装一波逼祭奠一下我关于ACM的回忆. 从大二上开始接触到大三下结束,接近两年的时间,对于大神们来说两年的确算不上时间,然而对于本弱来说就是大学的一半时光.大一的懵懂 ...
- 第一届山东省ACM——Phone Number(java)
Description We know that if a phone number A is another phone number B’s prefix, B is not able to be ...
- 第一届山东省ACM——Balloons(java)
Description Both Saya and Kudo like balloons. One day, they heard that in the central park, there wi ...
- ACM之鸡血篇
一匹黑马的诞生 故事还要从南京现场赛讲起,话说这次现场赛,各路ACM英雄豪杰齐聚南京,为争取亚洲总舵南京分舵舵主之职位,都使出了看 家本领,其中有最有实力的有京城两大帮清华帮,北大帮,南郡三大派上交派 ...
随机推荐
- 这次彻底理解了Object这个属性
1.实例化Object对象 实例化Object对象的方式有两种:使用Object构造器和使用对象的字面量.例如: var person1 = { name: '李四' }; var person2 = ...
- Django知识总结
一.什么是web框架? 框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支撑结构,使用框架可以帮你快速开发特定的系统,简单地说,就是你用别人搭建好的舞台来做表演. web应 ...
- wmv12下安装centos7
第一步:安装软件: vmw版本是12,并在vmw下安装centos为CentOS-7-x86_64-DVD-1708.iso: 第二步:修改vmw虚拟网络配置 1)配置VMnet8 修改ip等信息 点 ...
- 初学Java Web(9)——学生管理系统(简易版)总结
项目开始时间:2018年4月8日14:37:47 项目完成时间:2018年4月9日10:03:30 技术准备 这个项目是自己用于巩固 J2EE 相关知识的练手项目,非常简单,但是相关的功能却非常实用, ...
- JProfiler简明使用教程
JProfile是一款性能瓶颈分析工具,监控粒度可以细化到某一个类包,堪称神器!我安装了一下9.11的版本,并简单说说使用方法. 1:创建一个监控任务 2:选择tomcat版本 3:监控远程服务器 4 ...
- 前端开发必备之chrome插件
Chrome浏览器目前是网络上可用的最好的浏览器之一,并且自2011年11月超越了Firefox浏览器之后,已经成为了互联网上占主导地位的浏览器. 本篇文章将与大家分享一些与前端开发有关的实用的Chr ...
- 简明shell入门
- 网络安全实验室_上传关writeup
请上传一张jpg格式的图片 先传个图片码试试 我肯定乖嘛(#`Д´)ノ 气到改后缀 请上传一张jpg格式的图片 我猜是00截断,不信来试试 先在赋值1.php .jpg,接着去hex中找到空格改成00 ...
- Java操作属性文件与国际化
在前面讲到的java类集中的Hashtable中,有一个子类Properties,此类定义如下: public class Properties extends Hashtable<Object ...
- Scrapy命令行基本用法
1.创建一个新项目: scrapy startproject myproject 2.在新项目中创建一个新的spider文件: scrapy genspider mydomain mydomain.c ...