-
Notifications
You must be signed in to change notification settings - Fork 3
/
1025.c
64 lines (50 loc) · 1.2 KB
/
1025.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//1025 - Onde está o Mármore?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compara(const void *p1, const void *p2)
{ int *i = (int *)p1, *j = (int *)p2;
if (*i > *j)
return 1;
else
if (*i == *j)
return 0;
else
return -1;
}
int main ()
{
int N, Q, cont, vResp, c, *p, caso = 0, b;
scanf("%d %d", &N, &Q);
do{
int vetor[N+1];
caso++;
for(cont=0; cont<N; cont++){
scanf("%d", &vetor[cont]);
}
qsort(vetor, N, sizeof(int), compara);
for(c=0;c<Q;c++)
{
scanf("%d", &vResp);
p = (int *) bsearch(&vResp, vetor, N, sizeof(int), compara);
b = (int) (p - vetor);
for(cont=0;cont<b;cont++)
{
if ( vResp == vetor[cont])
{
b = cont;
break;
}
}
if(c==0)
printf("CASE# %d:\n", caso);
if(p != NULL)
printf("%d found at %d\n", vResp, (b+1));
else
printf("%d not found\n", vResp);
}
scanf("%d %d", &N, &Q);
} while (N!= 0 || Q != 0);
return 0;
}