#include<iostream>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<queue>#define ZUO 3#define YOU 0#define QIAN 2#define HOU 1using namespace std;int dir[4][2] = {1,0,0,1,0,-1,-1,0};//4个方向char s[300];int dui[7] = {0,6,5,4,3,2,1};int ok[7][7] = {{0}, {0,0,4,2,5,3,0}, {0,3,0,6,1,0,4}, {0,5,1,0,0,6,2}, {0,2,6,0,0,1,5}, {0,4,0,1,6,0,3}, {0,0,3,5,2,4,0}};//top&front,这个表的意义就是当top=i,front=j时候left的值是ok[i][j]struct node{ int top,front; int left,right; int back,bottom; int x,y;}t;node roll( node t,int i)//以第i的方向,对t进行滚动{ int m; t.x += dir[i][0]; t.y += dir[i][1]; if( i == QIAN ) { m = t.front; t.front = t.top; t.top = t.back; t.back = t.bottom; t.bottom = m; } if( i == YOU ) { m = t.right; t.right = t.top; t.top = t.left; t.left = t.bottom; t.bottom = m; } if( i == ZUO ) { m = t.right; t.right = t.bottom; t.bottom = t.left; t.left = t.top; t.top = m; } if( i == HOU ) { m = t.bottom; t.bottom = t.back; t.back = t.top; t.top = t.front; t.front = m; } return t;}int main(void){ //freopen("C:\Users\thinkpad\Desktop\out.txt","w",stdout); int a,b; char c; printf("Problem 2 by team xn"); while( scanf("%d%d",&a,&b) != EOF ) { printf("n"); if( !ok[a][b] ) { gets(s); printf("Invalid initial orientation:"); printf(" top = %d front = %dn",a,b); continue; } printf("Initial orientation:"); printf(" top = %d front = %dn",a,b); printf("Moves:"); t.top = a; t.front = b; t.bottom = dui[ t.top ]; t.back = dui[ t.front ]; t.left = ok[ t.top ][ t.front ]; t.right = dui[ t.left ]; t.x = t.y = 0; while( 1 ) { if( (c=getchar()) == 'n' ) break; c = getchar(); printf(" %c",c); switch(c) { case 'E':t = roll(t,YOU);break; case 'N':t = roll(t,HOU);break; case 'W':t = roll(t,ZUO);break; case 'S':t = roll(t,QIAN);break; default :break; } } printf("nFinal orientation and position:"); printf(" top = %d front = %d x =%4d y =%4dn", t.top,t.front,t.x,t.y); } printf("End of problem 2 by team xn"); return 0;}