程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdio> | |
#include <algorithm> | |
using namespace std; | |
int main(){ | |
int N,Q,a[10000],x,ptr,times = 1; | |
while(scanf("%d %d",&N,&Q)==2 && (N || Q)){ | |
for(int i = 0;i<N;i++) | |
scanf("%d",&a[i]); | |
sort(a,a+N);//排序 | |
printf("CASE# %d:\n",times++); | |
while(Q--){ | |
scanf("%d",&x); | |
ptr = lower_bound(a,a+N,x)-a; | |
//如果有找到 | |
if(a[ptr]==x) printf("%d found at %d\n",x,ptr+1); | |
//如果沒找到 | |
else printf("%d not found\n",x); | |
} | |
} | |
} |
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。