UVA10474 Where is the Marble?【排序】

参考:https://blog.youkuaiyun.com/q547550831/article/details/51326321

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 using namespace std;
 5 #define N 10000
 6 int main()
 7 {
 8     int n,q,count=0;
 9 
10     while (scanf("%d %d",&n,&q)!=EOF)
11     {
12         if (n==0&&q==0)
13         {
14             break;
15          } 
16         int m[N];
17         int i;
18         for (i=0;i<n;i++)
19         {
20             scanf("%d",&m[i]);
21         }
22         sort(m,m+n);
23         printf("CASE# %d:\n",++count);//此行要放在while前面!!! 
24         while (q--)
25         {
26             int temp;
27             scanf("%d",&temp);
28             int t=lower_bound(m,m+n,temp)-m;
29             if (m[t]==temp)
30             {
31                 printf("%d found at %d\n",temp,t+1);
32             }
33             else
34             {
35                 printf("%d not found\n",temp);
36             }
37         }
38     }
39     
40     return 0;
41 } 

 

转载于:https://www.cnblogs.com/hemeiwolong/p/9375078.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值