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 |
why wa# include <stdio.h> struct pos{ int x,y,z; int face; int status;//used for identify the man's head-direction }pos; void go(char,int); void walk(int); void turnleft(); void turnright(); void turnup(); void turndown(); void main() { int nOfcase; int nOfstep; char changeFace[10]; int steplen; scanf("%d",&nOfcase); while (nOfcase--){ pos.x=pos.y=pos.z=pos.face=pos.status=0; pos.status=2; scanf("%d",&nOfstep); while(nOfstep--){ scanf("%s %d",changeFace,&steplen); go(changeFace[0],steplen); } printf("%d %d %d %d\n",pos.x,pos.y,pos.z,pos.face); } } void go(char face,int len) { switch (face){ case 'f':walk(len);break; case 'b':pos.face = (3+pos.face) % 6;//turnback; walk(len);break; case 'l':turnleft(); walk(len);break; case 'r':turnright(); walk(len);break; case 'u':turnup(); walk(len);break; case 'd':turndown(); walk(len);break; } } void turnleft() { switch(pos.face){ case 0: switch(pos.status){ case 1:pos.face=2;break; case 4:pos.face=5;break; case 2:pos.face=4;break; case 5:pos.face=1;break; } break; case 3: switch(pos.status){ case 1:pos.face=5;break; case 4:pos.face=2;break; case 2:pos.face=1;break; case 5:pos.face=4;break; } break; case 1: switch(pos.status){ case 0:pos.face=5;break; case 3:pos.face=2;break; case 2:pos.face=0;break; case 5:pos.face=3;break; } break; case 4: switch(pos.status){ case 0:pos.face=2;break; case 3:pos.face=5;break; case 2:pos.face=3;break; case 5:pos.face=0;break; } break; case 2: switch(pos.status){ case 0:pos.face=4;break; case 1:pos.face=0;break; case 3:pos.face=1;break; case 4:pos.face=3;break; } break; case 5: switch(pos.status){ case 0:pos.face=1;break; case 1:pos.face=3;break; case 3:pos.face=4;break; case 4:pos.face=0;break; } break; } } void turnright() { switch(pos.face){ case 0: switch(pos.status){ case 1:pos.face=5;break; case 4:pos.face=2;break; case 2:pos.face=1;break; case 5:pos.face=4;break; } break; case 3: switch(pos.status){ case 1:pos.face=2;break; case 4:pos.face=5;break; case 2:pos.face=4;break; case 5:pos.face=1;break; } break; case 1: switch(pos.status){ case 0:pos.face=2;break; case 3:pos.face=5;break; case 2:pos.face=3;break; case 5:pos.face=0;break; } break; case 4: switch(pos.status){ case 0:pos.face=5;break; case 3:pos.face=2;break; case 2:pos.face=0;break; case 5:pos.face=3;break; } break; case 2: switch(pos.status){ case 0:pos.face=1;break; case 1:pos.face=3;break; case 3:pos.face=4;break; case 4:pos.face=0;break; } break; case 5: switch(pos.status){ case 0:pos.face=4;break; case 1:pos.face=0;break; case 3:pos.face=1;break; case 4:pos.face=3;break; } break; } } void turnup() { switch(pos.face){ case 0: switch(pos.status){ case 1:pos.face=1;pos.status=3;break; case 4:pos.face=4;pos.status=3;break; case 2:pos.face=2;pos.status=3;break; case 5:pos.face=5;pos.status=3;break; } break; case 3: switch(pos.status){ case 1:pos.face=1;pos.status=0;break; case 4:pos.face=4;pos.status=0;break; case 2:pos.face=2;pos.status=0;break; case 5:pos.face=5;pos.status=0;break; } break; case 1: switch(pos.status){ case 0:pos.face=0;pos.status=4;break; case 3:pos.face=3;pos.status=4;break; case 2:pos.face=2;pos.status=4;break; case 5:pos.face=5;pos.status=4;break; } break; case 4: switch(pos.status){ case 0:pos.face=0;pos.status=1;break; case 3:pos.face=3;pos.status=1;break; case 2:pos.face=2;pos.status=1;break; case 5:pos.face=5;pos.status=1;break; } break; case 2: switch(pos.status){ case 0:pos.face=0;pos.status=5;break; case 3:pos.face=3;pos.status=5;break; case 1:pos.face=1;pos.status=5;break; case 4:pos.face=4;pos.status=5;break; } break; case 5: switch(pos.status){ case 0:pos.face=0;pos.status=2;break; case 3:pos.face=3;pos.status=2;break; case 1:pos.face=1;pos.status=2;break; case 4:pos.face=4;pos.status=2;break; } break; } } void turndown() { switch(pos.face){ case 0: switch(pos.status){ case 1:pos.face=4;pos.status=0;break; case 4:pos.face=1;pos.status=0;break; case 2:pos.face=5;pos.status=0;break; case 5:pos.face=2;pos.status=0;break; } break; case 3: switch(pos.status){ case 1:pos.face=4;pos.status=3;break; case 4:pos.face=1;pos.status=3;break; case 2:pos.face=5;pos.status=3;break; case 5:pos.face=2;pos.status=3;break; } break; case 1: switch(pos.status){ case 0:pos.face=3;pos.status=1;break; case 3:pos.face=0;pos.status=1;break; case 2:pos.face=5;pos.status=1;break; case 5:pos.face=2;pos.status=1;break; } break; case 4: switch(pos.status){ case 0:pos.face=3;pos.status=4;break; case 3:pos.face=0;pos.status=4;break; case 2:pos.face=5;pos.status=4;break; case 5:pos.face=2;pos.status=4;break; } break; case 2: switch(pos.status){ case 0:pos.face=3;pos.status=2;break; case 3:pos.face=0;pos.status=2;break; case 1:pos.face=4;pos.status=2;break; case 4:pos.face=1;pos.status=2;break; } break; case 5: switch(pos.status){ case 0:pos.face=3;pos.status=5;break; case 3:pos.face=0;pos.status=5;break; case 1:pos.face=4;pos.status=5;break; case 4:pos.face=1;pos.status=5;break; } break; } } void walk(int l) { // printf("face%d status%d\n",pos.face,pos.status); switch(pos.face){ case 0:pos.x += l;break; case 1:pos.y += l;break; case 2:pos.z += l;break; case 3:pos.x -= l;break; case 4:pos.y -= l;break; case 5:pos.z -= l;break; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator