UVA10474 - Where is the Marble?

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1415

水题 简单排序查找 快排+哈希

View Code
 1 #include <stdio.h>

 2 #include<string.h>

 3 int cmp(const void*a,const void *b)

 4 {

 5     return *(int *)a-*(int *)b;

 6 }

 7 int main()

 8 {

 9     int i,j,n, m, a[10001],b[10001],x[10001],k = 0;

10     while(scanf("%d%d", &n, &m)!=EOF)

11     {

12         if(n == 0&&m == 0)

13         break;

14         k++;

15         memset(b,0,sizeof(b));

16         for(i = 0 ; i < n ; i++)

17             scanf("%d", &a[i]);

18         qsort(a,n,sizeof(a[0]),cmp);

19         for(i = 0;  i < n ; i++)

20         {

21             if(!b[a[i]])

22             b[a[i]] = i+1;

23         }

24         for(i = 1 ; i <= m ; i++)

25             scanf("%d", &x[i]);

26         printf("CASE# %d:\n",k);

27         for(i = 1 ; i <= m ; i++)

28         {

29             if(b[x[i]]!=0)

30             printf("%d found at %d\n",x[i],b[x[i]]);

31             else

32             printf("%d not found\n",x[i]);

33         }

34     }

35     return 0;

36 }

 

你可能感兴趣的:(where)