📄 1152.cpp
字号:
/* This Code is Submitted by wywcgs for Problem 1152 on 2005-10-02 at 10:57:23 */
#include <cstdio>
#include <cstring>
class LinkedList {
public:
LinkedList *next;
LinkedList *before;
int order;
LinkedList(int i) {
next = NULL;
before = NULL;
order = i;
}
void clear() {
LinkedList *p = this;
LinkedList *q;
while(true) {
if(p->before != NULL) {
p->before->next = NULL;
}
p->before = NULL;
if(p->next != NULL) {
q = p;
p = p->next;
q->next = NULL;
} else {
break;
}
}
}
void moveOnto(LinkedList *l) {
this->clear();
if(l->next != NULL) {
l->next->clear();
}
l->next = this;
this->before = l;
}
void moveOver(LinkedList *l) {
LinkedList *p = l;
while(p->next != NULL) {
p = p->next;
}
this->clear();
p->next = this;
this->before = p;
}
void pileOnto(LinkedList *l) {
if(l->next != NULL) {
l->next->clear();
}
if(this->before != NULL) {
this->before->next = NULL;
this->before = NULL;
}
l->next = this;
this->before = l;
}
void pileOver(LinkedList *l) {
LinkedList *p = l;
while(p->next != NULL) {
p = p->next;
}
if(this->before != NULL) {
this->before->next = NULL;
this->before = NULL;
}
p->next = this;
this->before = p;
}
};
int main()
{
LinkedList *list[25], *p, *q;
int i;
int n, a, b;
char o[8], v[8];
bool same, noneN, noneB;
for(i = 0; i < 25; i++) {
list[i] = new LinkedList(i);
}
scanf("%d", &n);
while(true) {
scanf("%s", o);
if(!strcmp(o, "quit")) {
break;
} else {
scanf("%d %s %d", &a, v, &b);
same = false;
noneN = false;
noneB = false;
p = list[a];
q = list[a];
while(true) {
if(p == list[b] || q == list[b]) {
same = true;
break;
} else {
if(noneN && noneB) {
break;
}
if(p->next != NULL) {
p = p->next;
} else {
noneN = true;
}
if(q->before != NULL) {
q = q->before;
} else {
noneB = true;
}
}
}
if(same) {
continue;
} else {
if(!strcmp(o, "move")) {
if(!strcmp(v, "onto")) {
list[a]->moveOnto(list[b]);
} else {
list[a]->moveOver(list[b]);
}
} else {
if(!strcmp(v, "onto")) {
list[a]->pileOnto(list[b]);
} else {
list[a]->pileOver(list[b]);
}
}
}
}
}
for(i = 0; i < n; i++) {
printf("%d:", i);
if(list[i]->before == NULL) {
p = list[i];
while(true) {
printf(" %d", p->order);
if(p->next != NULL) {
p = p->next;
} else {
break;
}
}
}
putchar('\n');
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -