-
Notifications
You must be signed in to change notification settings - Fork 0
/
6_2.c
85 lines (78 loc) · 1.65 KB
/
6_2.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <stdio.h>
typedef struct List{
char data[8];
int next;
}List;
void insert(List *arr, int index, char data[8], int *n, int *fst){
if (index == -1){
for (int i = 0; i < 8; i++){
arr[*n].data[i] = data[i];
}
arr[*n].next = *fst;
*fst = *n;
printf("%d\n", *n);
*n += 1;
return;
}
for (int i = 0; i < 8; i++){
arr[*n].data[i] = data[i];
}
arr[*n].next = arr[index].next;
arr[index].next = *n;
printf("%d\n", *n);
*n += 1;
}
void pop(List *arr, int index, int *n, int *fst) {
int tmp;
if (index == -1){
printf("%s\n", arr[*fst].data);
*fst = arr[*fst].next;
}
else{
tmp = arr[index].next;
arr[index].next = arr[tmp].next;
printf("%s\n", arr[tmp].data);
}
}
void printList(List *arr, int fst){
if (fst == -1){
printf("\n");
}
else{
while (arr[fst].next != -1) {
printf("%s\n", arr[fst].data);
fst = arr[fst].next;
}
printf("%s\n", arr[fst].data);
}
}
int main(){
List array[200002] = {0};
int t, n, first, quest, next, temp, index;
char tmp[8];
scanf("%d", &t);
for (int i = 0; i < t; i++){
scanf("%d%d%d", &n, &first, &quest);
for (int j = 0; j < n; j++){
scanf("%s", tmp);
scanf("%d", &next);
for (int g = 0; g < 8; g++){
array[j].data[g] = tmp[g];
}
array[j].next = next;
}
for (int j = 0; j < quest; j++){
scanf("%d%d", &temp, &index);
if (temp == 0){
scanf("%s", tmp);
insert(array, index, tmp, &n, &first);
}
else {
pop(array, index, &n, &first);
}
}
printf("===\n");
printList(array, first);
printf("===\n");
}
}