| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
WA 的不行了。。。。In Reply To:help Posted by:sunny_fable at 2007-04-23 15:11:46 #include"cstdio"
#include"string.h"
#define max 25
int s[max][max],num[max],p[max],q[max];
int cmp(char r[])
{
if(!strcmp(r,"move")) return 1;
if(!strcmp(r,"pile")) return 2;
if(!strcmp(r,"onto")) return 3;
if(!strcmp(r,"over")) return 4;
}
int main()
{
int n , a , b , op , i , j , k , c ,d , tp1[max] , tp2[max] , t1 , t2;
char r1[10],r2[10];
scanf("%d",&n);
// while(scanf("%d",&n) != EOF)
{
for(i = 0;i < n;i++)
{
s[i][0] = p[i] = i;
num[i] = 1;q[i] = 0;
}
while(1)
{
scanf("%s",r1); if(!strcmp(r1,"quit")) break;
scanf("%d %s %d",&a,r2,&b);
if(p[a] == p[b]) continue;
c = cmp(r1);d = cmp(r2);
if(c == 1 && d == 3) op = 1;
else if(c == 1 && d == 4) op = 2;
else if(c == 2 && d == 3) op = 3;
else if(c == 2 && d == 4) op = 4;
switch(op)
{
case 1:
{
i = q[b]+1;j = p[b];
for(;i < num[j];i++)
{
c = s[j][i];s[c][0] = c;p[c] = c;q[c] = 0;
}
num[p[b]] = q[b]+1;
i = q[a]+1;j = p[a];
for(;i < num[j];i++)
{
c = s[j][i];s[c][0] = c;p[c] = c;q[c] = 0;
}
num[p[a]] = q[a];
s[p[b]][num[p[b]]++] = a;p[a] = p[b];q[a] = num[p[b]]-1;
}
break;
case 2:
{
j = p[a];i=q[a]+1;c = q[a];
for(;i < num[j];i++)
{
c = s[j][i];s[c][0] = c;p[c] = c;q[c] = 0;
}
s[p[b]][num[p[b]]] = a;p[a] = p[b];q[a] = num[p[b]]++;
num[j] = c;
}
break;
case 3:
{
i = q[b]+1;j = p[b];
for(;i < num[j];i++)
{
c = s[j][i];s[c][0] = c;p[c] = c;q[c] = 0;
}
num[p[b]] = q[b]+1;
c = q[a];j = p[a];
for(i = q[a];i < num[j];i++)
{
s[p[b]][num[p[b]]] = s[j][i];
p[s[j][i]] = p[b];q[s[j][i]] = num[p[b]]++;
}
num[j] = c;
}
break;
case 4:
{
j = p[a];c = q[a];
for(i = q[a];i < num[j];i++)
{
s[p[b]][num[p[b]]] = s[j][i];
p[s[j][i]] = p[b];q[s[j][i]] = num[p[b]]++;
}
num[j] = c;
}
break;
}
}
for(i = 0;i < n;i++)
{
printf("%d:",i);
for(j = 0;j < num[i];j++)
printf(" %d",s[i][j]);
printf("\n");
}
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator