D - Where is the Marble?
题意:对一组整数进行排序,排序后找出给定数字在数组中的位置。
题解:先排序,再遍历找。
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
int n,m;
int num[10005];
int count = 0;
while(scanf("%d%d",&n,&m) && n && m)
{
printf("CASE# %d:\n",++count);
int i;
for(i = 0;i < n;i++)
{
scanf("%d",&num[i]);
}
sort(num,num + n);
int x;
while(m--)
{
scanf("%d",&x);
for(i = 0;i < n;i++)
{
if(x == num[i])
{
printf("%d found at %d\n",x,i + 1);
break;
}
}
if(i >= n)
{
printf("%d not found\n",x);
}
}
}
return 0;
}