这题...看了一下,觉得怎么可以这么简单(╯‵□′)╯︵┴─┴
是又看了很久,想找出陷阱来...失败了╮(╯▽╰)╭
应该是作为二分搜索的练习题吧...
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int comp (const void *_a, const void *_b)
{
int *a = (int *)_a;
int *b = (int *)_b;
return *a - *b;
}
int marble[15000];
int main()
{
//freopen("input.txt", "r", stdin);
int i, j;
int count = 1, allcount = 1;
int n, m;
int temp;
while (scanf("%d%d", &n, &m))
{
memset(marble, 0, sizeof(marble));
if (n == 0 && m == 0)
break;
printf("CASE# %d:\n", allcount++);
for (i = 0; i < n; i++) //读取大理石的数字
scanf("%d", &marble[i]);
//排序
qsort(marble, n, sizeof(marble[0]), comp);
for (i = 0; i < m; i++)
{
count = 1;
scanf("%d", &temp);
for (j = 0; j < n; j++)
{
if (marble[j] == temp)
{
printf("%d found at %d\n", temp, j + 1);
break;
}
if (j == n - 1)
printf("%d not found\n", temp);
}
}
}
return 0;
}