Imagine looking at a six-sided die so two sides face east-west, two face north-south, and the last two sides face up-down. You could write down the number of dots on each side in the order: east, west, north, south, up, down.
Normal dice are labeled so that the sum of opposing sides sum to seven. This constraint is sufficient to reduce dice into two categories, "Left handed" and "Right handed." Left handed dice can be oriented so that the east face is 1, the north face is 2, and the down face is 3. Right handed dice can be oriented so that the east face is 1, the north face is 2, and the up face is 3.
In this problem, given the face values of a sequence of dice, you are to determine the handedness of the dice.
The input file will contain a sequence of one or more face descriptions of a die. These will be written as six digits (not separated by white space) on a single line. The numbers will represent (in order) the face values of the east, west, north, south, up, and down faces of the given die.
Other than the standard leader and trailer, the output file simply has the word "left" or "right" for each dice in the input file.
162534
162543
526134
right
left
left
//ans[1]-ans[6]分别记录 东 西 北 南 上 下 的值,我们可以确定最后一定要转到:
//ans[1]=1,ans[3]=2,即 the east face is 1, the north face is 2,
//为了判断是 left或是 right ,我们要先把 东 面转到 1 ,再把 北 面转到 2,
//最后如果 上 面是3,则是right; 如果 下 面是3,则是left
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
char ch[10];
int ans[10],tmp;
while(cin>>ch+1)
{
for(int i=1;i<=6;++i)
ans[i]=ch[i]-'0';
if(ans[5]==1||ans[6]==1) //如果 1 是在 上 或 下 面,则需要先把 1 转到 水平面(东 西 北 南)
{
tmp=ans[5];
ans[5]=ans[4];ans[4]=ans[6];ans[6]=ans[3];
ans[3]=tmp;
}
while(ans[1]!=1) //在水平面进行旋转,因为每转 4 步就能回到原来状态,所以肯定可以在 3 步内把 东 面转到 1
{
tmp=ans[2];
ans[2]=ans[4];ans[4]=ans[1];ans[1]=ans[3];
ans[3]=tmp; //水平面的旋转按照:北->东->南->西->北,即ans[3]->ans[1]->ans[4]->ans[2]->ans[3]
}
while(ans[3]!=2) //在垂直面进行旋转
{
tmp=ans[5];
ans[5]=ans[4];ans[4]=ans[6];ans[6]=ans[3];
ans[3]=tmp; //垂直面的旋转按照:北->下->南->上->北,即ans[3]->ans[6]->ans[4]->ans[5]->ans[3]
}
if(ans[5]==3) //ans[5]==3表示 上 面是3
printf("right\n");
else
printf("left\n");
}
return 0;
}