fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <vector>
  5. #include <bitset>
  6. #include <stdio.h>
  7. #include <math.h>
  8. using namespace std;
  9. typedef std::vector<int> vi;
  10. typedef std::vector<pair<int, int> > vii;
  11. #define FOR(l) for(vi::iterator it=l.begin();it!=l.end();it++)
  12. #define FOR_L(l, s, e) for(vi::iterator it=l.begin()+s;it!=l.end()-e;it++)
  13.  
  14. //----------Main source code -----------------//
  15. int main() {
  16. int n, q, t, ca=1, pos;
  17. vi::iterator i;
  18. while(cin>>n>>q&&n&&q){
  19. vi l;
  20. while(n--) cin>>t, l.push_back(t);
  21. sort(l.begin(), l.end());
  22. printf("CASE# %d:\n",ca++);
  23. while(q--){
  24. cin>>t;
  25. i=lower_bound(l.begin(),l.end(), t);
  26. pos=i-l.begin();
  27. if(i == l.end() || *i!=t) printf("%d not found", t);
  28. else printf("%d found at %d",t, pos+1);
  29. cout<<endl;
  30. }
  31. }
  32. return 0;
  33.  
  34. }
Success #stdin #stdout 0s 3436KB
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