UVa 10474 - Where is the Marble?
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <bitset> #include <stdio.h> #include <math.h> using namespace std; typedef std::vector<int> vi; typedef std::vector<pair<int, int> > vii; #define FOR(l) for(vi::iterator it=l.begin();it!=l.end();it++) #define FOR_L(l, s, e) for(vi::iterator it=l.begin()+s;it!=l.end()-e;it++) //----------Main source code -----------------// int main() { int n, q, t, ca=1, pos; vi::iterator i; while(scanf("%d %d",&n, &q)&&n&&q){ vi l; while(n--) scanf("%d",&t), l.push_back(t); sort(l.begin(), l.end()); printf("CASE# %d:\n",ca++); while(q--){ cin>>t; i=lower_bound(l.begin(),l.end(), t); pos=i-l.begin(); if(i == l.end() || *i!=t) printf("%d not found", t); else printf("%d found at %d",t, pos+1); cout<<endl; } } return 0; }
Ideone: http://ideone.com/dRSVuK
Comments
Post a Comment