题目:一个骰子,从上往下看,正、北、西的面为123;给你从上面看的旋转序列,问最后顶面是几。
分析:模拟。建立每种旋转中,转前和转后的每个面之间的对应关系,直接转换即可。
说明:想起多年以前写过的Android上面的魔方游戏了(⊙_⊙)。
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
char Now[7],New[7];
char turn[4][7] = {
/*"012345"*///初始
"402351", //上北 ,
"152304", //下南
"310542", //左西
"215043"};//右东
int main()
{
int n;
char buf[10];
while ( cin >> n && n ) {
strcpy( New, "123456" );
while ( n -- ) {
strcpy( Now, New );
cin >> buf;
int forword = 0;
if ( buf[0] == 'n' )forword = 0;
if ( buf[0] == 's' )forword = 1;
if ( buf[0] == 'w' )forword = 2;
if ( buf[0] == 'e' )forword = 3;
for ( int i = 0 ; i < 6 ; ++ i )
New[i] = Now[turn[forword][i]-'0'];
}
cout << New[0] << endl;
}
return 0;
}