-
Notifications
You must be signed in to change notification settings - Fork 0
/
1025.c
59 lines (51 loc) · 1.27 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
#include <stdio.h>
typedef struct
{
int valor_marmore;
} marmore;
int main()
{
int N, Q; scanf("%d %d", &N, &Q);
int caso = 1;
while(N || Q)
{
printf("CASE# %d:\n", caso);
marmore marmores[N];
for(int i=0; i<N; i++)
{
scanf("%d", &marmores[i].valor_marmore);
}
for(int i=1; i<N; i++)
{
int index = i;
while((index > 0) && (marmores[index].valor_marmore < marmores[index-1].valor_marmore))
{
marmore temp = marmores[index];
marmores[index] = marmores[index-1];
marmores[index-1]= temp;
index--;
}
}
for(int i=0; i<Q; i++)
{
int consulta; scanf("%d", &consulta);
int achou = 0;
for(int j = 0; j<N; j++)
{
if(marmores[j].valor_marmore == consulta)
{
printf("%d found at %d\n", consulta, j+1);
achou = 1;
break;
}
}
if(!achou)
{
printf("%d not found\n", consulta);
}
}
scanf("%d %d", &N, &Q);
caso++;
}
return 0;
}