fork(1) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void Find(long long n,long long arr[],long long qs){
  6. long long s=0,e=n-1,mid=0,ind=0;
  7. bool f=0;
  8. while(s<=e){
  9. mid=(s+e)/2;
  10. if(arr[mid]==qs){ind=mid; e=mid-1; f=1;}
  11. else if(arr[mid]<qs)s=mid+1;
  12. else e=mid-1;
  13. }
  14. if(f==1){cout<<qs<<" found at "<<ind+1<<endl;}
  15. else {cout<<qs<<" not found"<<endl;}
  16.  
  17. }
  18. long long arr[10001],qs,t=0;
  19. int main()
  20. {
  21. long long n,q;
  22. while(true){
  23. cin>>n>>q;
  24. if(n==0&&q==0){break;}
  25. for(int i=0;i<n;i++){
  26. cin>>arr[i];
  27. }
  28. sort(arr,arr+n);
  29. t++;
  30. cout<<"CASE#"<<" "<<t<<":"<<endl;
  31. for(int i=0;i<q;i++){
  32. cin>>qs;
  33. Find(n,arr,qs);
  34. }
  35. //long long arr[10001];
  36. }
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 4316KB
stdin
4 1
2
3
5
1
5
5 2
1
3
3
3
1
2
3
0 0
stdout
CASE# 1:
5 found at 4
CASE# 2:
2 not found
3 found at 3