I wrote the code myself.
#include <iostream>
#include <algorithm>
using namespace Std;
int main ()
{
int N,a[100],b[100],q,flag;
int k=1;
while (CIN>>N>>Q)
{
for (int i=0;i<n;i++)
{
cin>>a[i];
}
for (int j=0;j<q;j++)
{
cin>>b[j];
}
Sort (a,a+n);
for (int j=0;j<q;j++)
{
flag=0;
cout<< "case#" <<k++<<endl;
for (int i=0;i<n;i++)
{
if (A[i]==b[j])
{
cout<<b[j]<< "found at" <<i+1<<endl;
flag=1;
Break
}
}
if (flag==0)
{
cout<<b[j]<< "Not Found" <<endl;
}
}
}
return 0;
}
The code written on the book
#include <iostream>
#include <algorithm>
using namespace Std;
int main ()
{
int n,a[100],q,x;
int k=1;
while (CIN>>N>>Q)
{
for (int i=0;i<n;i++)
{
cin>>a[i];
}
Sort (a,a+n);
cout<< "case#" <<k++<<endl;
while (q--)
{
cin>>x;
int P=lower_bound (A,A+N,X)-a;//is greater than or equal to the first number of x subscript
if (a[p]==x)
cout<<x<< "found at" <<p+1<<endl;
Else
cout<<x<< "Not Found" <<endl;
}
}
return 0;
}
Hey, I'm still a vegetable.
Where's the marble? UVa 10474