参考:https://blog.csdn.net/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
时间: 2024-10-17 21:59:37