UVa 10474 大理石在哪儿
来源:互联网 发布:sql plus 编辑:程序博客网 时间:2024/05/16 00:52
题目描述:
Raju and Meena love to play with Marbles. They have got a lot ofmarbles with numbers written on them. At the beginning, Raju wouldplace the marbles one after another in ascending order of the numberswritten on them. Then Meena would ask Raju to find the first marblewith a certain number. She would count 1...2...3. Raju gets one pointfor correct answer, and Meena gets the point if Raju fails. After somefixed number of trials the game ends and the player with maximumpoints wins. Today it’s your chance to play as Raju. Being the smartkid, you’d be taking the favor of a computer. But don’t underestimateMeena, she had written a program to keep track how much time you’retaking to give all the answers. So now you have to write a program,which will help you in your role as Raju.InputThere can be multiple test cases. Total no of test cases is less than 65. Each test case consists beginswith 2 integers: N the number of marbles and Q the number of queries Mina would make. The nextN lines would contain the numbers written on the N marbles. These marble numbers will not comein any particular order. Following Q lines will have Q queries. Be assured, none of the input numbersare greater than 10000 and none of them are negative.Input is terminated by a test case where N = 0 and Q = 0.OutputFor 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 whetheror not the query number is written upon any of the marbles. The two different formats are describedbelow:• ‘x found at y’, if the first marble with number x was found at position y. Positions are numbered1, 2, . . . , N.• ‘x not found’, if the marble with number x is not present.Look at the output for sample input for details.Sample Input4 1235155 213331230 0Sample OutputCASE# 1:5 found at 4CASE# 2:2 not found3 found at 3
题目分析:
排序+查找
AC代码;
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<cmath>using namespace std;int m,n;int v[10005];int main(){ int cnt=1; while(1) { scanf("%d%d",&m,&n); if(m==0&&n==0) break; printf("CASE# %d:\n",cnt++); for(int i=1;i<=m;i++) scanf("%d",&v[i]); sort(v+1,v+m+1); while(n--) { int x; scanf("%d",&x); for(int i=1;i<=m;i++) { if(x==v[i]) { printf("%d found at %d\n",x,i); break; } if(i==m) printf("%d not found\n",x); } } } return 0;}
- UVa 10474 大理石在哪儿
- 例题:大理石在哪儿(UVa 10474)
- UVa 10474 Where is the Marble?(大理石在哪儿)
- 大理石在哪儿(UVa 10474)(排序与检索)
- uva 10474 Where is the Marble?(大理石在哪儿)
- 大理石在哪儿(Where is the marble?,UVa 10474)
- 大理石在哪儿 (排序和查找) UVA
- 大理石在哪儿
- STL初步:大理石在哪儿?
- C++之大理石在哪儿?
- UVa 10474 大理石在哪?
- UVa 10474 大理石在哪?
- UVA 10474 大理石在哪里
- 10474 - 大理石在哪儿Where is the Marble?(排序+检索)
- 算法入门经典:大理石在哪儿
- uva10474大理石在哪儿where is the marble?
- 大理石在哪儿?(Stl lower_bound用法)
- 例题5-1 大理石在哪儿 UVa10474
- 96. Unique Binary Search Trees
- 在JAVA中如何跳出当前的多重嵌套循环?
- 简单的登录注册原型系统
- 看国外拳击啦
- Java与RabbitMQ(二)启动rabbitmq web管理后台插件
- UVa 10474 大理石在哪儿
- 浏览器渲染引擎学习总结
- Android开发中WebView的使用方法
- [LeetCode]257. Binary Tree Paths
- ALOHA算法衍生系列:Iterative Interference Cancellation在ALOHA算法中的应用总结
- 我的Ubuntu 开发环境配置
- ajax在用户登录时异步验证用户合法性
- QST青软实训学员学习总结
- Android开发中AlertDialog的使用方法