53 lines
922 B
C
53 lines
922 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define SIZE 50
|
|
|
|
char stack[10*SIZE];
|
|
int ptr[10];
|
|
|
|
int move(int source, int dest, int q) {
|
|
ptr[dest]-= q;
|
|
memcpy(stack + ptr[dest], stack + ptr[source], q);
|
|
ptr[source]+=q;
|
|
}
|
|
int insert(int index, char val) {
|
|
stack[ptr[index]] = val;
|
|
ptr[index]++;
|
|
}
|
|
|
|
void init_ptrs() {
|
|
for (int i=0; i<10; i++) {
|
|
ptr[i] = i*SIZE;
|
|
}
|
|
}
|
|
|
|
int main () {
|
|
char cur[20];
|
|
int cur_sum = 0;
|
|
int max = 0;
|
|
init_ptrs();
|
|
int k = 1;
|
|
while (fgets(cur,5,stdin) !=NULL) {
|
|
if (strlen(cur) < 4 || cur[1] == '1') break;
|
|
if (cur[1] != ' ') {
|
|
insert(k,cur[1]);
|
|
}
|
|
k++;
|
|
if (k > 9) k=1;
|
|
}
|
|
init_ptrs();
|
|
char c;
|
|
while (c = getchar(), c != '\n'); // skip lines
|
|
while (c = getchar(), c != '\n'); // skip lines
|
|
int q, src, dst;
|
|
while (scanf("move %d from %d to %d\n", &q, &src, &dst) != EOF) {
|
|
move(src,dst,q);
|
|
}
|
|
for (int i=1; i<10; i++)
|
|
putchar(stack[ptr[i]]);
|
|
|
|
|
|
}
|