-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1167.c
More file actions
58 lines (50 loc) · 1.5 KB
/
1167.c
File metadata and controls
58 lines (50 loc) · 1.5 KB
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
#include <stdio.h>
#include <stdlib.h>
#define MAX 31
struct Node {
int token;
char name[MAX];
int next, previous;
};
int main(int argc, char *argv[])
{
struct Node v[100];
int n;
while(scanf("%d", &n) && n) {
if(n == 1) {
scanf(" %30s %d", v[0].name, &v[0].token);
v[0].next = v[0].previous = 0;
} else {
int i;
for(i=0; i<n; i++) {
scanf(" %30s %d", v[i].name, &v[i].token);
v[i].next = i+1;
v[i].previous = i-1;
}
v[i-1].next = 0; //end is pointing to the beginning;
v[0].previous = i-1; //beginning is pointing to end;
}
/*int teste=0;
while(v[teste].next != 0) {
printf("%s %d previous: %d next: %d\n", v[teste].name, v[teste].token, v[teste].previous, v[teste].next);
teste = v[teste].next;
}*/
int steps = v[0].token, c=0, qtd = n;
while(qtd != 1) {
if(steps & 1) {
for(int i=0; i<steps; i++)
c = v[c].next;
} else {
for(int i=0; i<steps; i++)
c = v[c].previous;
}
//printf("to be removed: %s\n", v[c].name);
v[v[c].next].previous = v[c].previous;
v[v[c].previous].next = v[c].next;
steps = v[c].token;
qtd--;
}
printf("Vencedor(a): %s\n", v[v[c].next].name);
}
return 0;
}