UVaOJ 10474 大理石在哪?
来源:互联网 发布:广播电台软件 编辑:程序博客网 时间:2024/04/28 17:51
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.
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define maxn 10000+10int num[maxn],que[maxn];int main(){int N,Q,i,cnt=1;while(scanf("%d%d",&N,&Q)!=EOF && N && Q){for(i=0;i<N;i++) scanf("%d",&num[i]); for(i=0;i<Q;i++) scanf("%d",&que[i]);sort(num,num+N);//升序排序printf("CASE# %d:\n",cnt++);for(int i=0;i<Q;i++){int j;for(j=0;j<N;j++)if(que[i]==num[j]){printf("%d found at %d\n",que[i],j+1);break;}if(j==N)printf("%d not found\n",que[i]);}}return 0;}
- UVaOJ 10474 大理石在哪?
- uvaoj-12474:大理石在哪里
- UVa 10474 大理石在哪?
- UVa 10474 大理石在哪?
- 大理石在哪
- 大理石在哪
- UVA 10474 大理石在哪里
- 紫书章五 大理石在哪 UVA 10474(stl排序查找)
- 大理石在哪(Where is the Marble?, uva 10474)
- Uva 10474(lower_bound()的使用) 大理石在哪
- 大理石在哪?(Where is the Marble?, UVa 10474)代码
- 例题5-1 UVA 10474 Where is the Marble?大理石在哪?
- UVa 10474 大理石在哪儿
- 大理石
- 例题:大理石在哪儿(UVa 10474)
- 算法之路二:刘汝佳算法竞赛入门经典:STL排序与检索 大理石在哪 UVA10474
- UVaOJ
- UVa 10474 Where is the Marble?(大理石在哪儿)
- __declspec(dllimport)
- nohup命令的使用
- IDR、CRA、BLA、RASL、RADL、closed-gop、open-gop
- sql server 2008 不允许保存更改,您所做的更改要求删除并重新创建以下表 的解决办法
- java 内存区域——运行时数据区(堆、栈)
- UVaOJ 10474 大理石在哪?
- 2502. Digit Generator
- C#中的partial class(部分类)
- JavaScript跨域访问小结
- 5-2. 念数字
- Codeforces 448D Multiplication Table
- 贪心和DP POJ2287 田忌赛马
- 9 个用来加速 HTML5应用的方法
- Java中的递归原理分析