UVA_10474
You can use Hash to read, sort, and traverse the Marbles array and assign values to the hash array, hash [I] indicates the position where the Marble labeled I appears for the first time.
After reading a Q, you only need to determine whether the elements in the corresponding hash array are assigned a value and output accordingly.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int a[10010],hash[10010];
int cmp(const void *_p,const void *_q)
{
int *p=(int *)_p;
int *q=(int *)_q;
return *p-*q;
}
int main()
{
int i,j,k,N,Q,t;
t=0;
while(1)
{
scanf("%d%d",&N,&Q);
if(N==0)
break;
printf("CASE# %d:\n",++t);
for(i=0;i<N;i++)
scanf("%d",&a[i]);
qsort(a,N,sizeof(a[0]),cmp);
memset(hash,-1,sizeof(hash));
for(i=0;i<N;i++)
if(hash[a[i]]==-1)
hash[a[i]]=i+1;
for(i=0;i<Q;i++)
{
scanf("%d",&k);
if(hash[k]==-1)
printf("%d not found\n",k);
else
printf("%d found at %d\n",k,hash[k]);
}
}
return 0;
}