1128. DICE
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
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.
Input
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.
Output
Other than the standard leader and trailer, the output file simply has the word "left" or "right" for each dice in the input file.
Sample Input
162534162543526134
Sample Output
rightleftleft
题目分析
左手骰子的east, west, north, south, up, and down一定可以变为162543
右手骰子的east, west, north, south, up, and down一定可以变为162534
我们只要确保str[0]==1,str[2]==2,通过查看str[4]即可知道是左手还是右手
策略是: 使1朝向水平面->使1朝向east->使2朝向north
想象有两个手指固定了一个方向,则骰子只能水平或垂直方向旋转
想通第一步对应的变化,注意第二第三步的变化
#include <iostream>
int main()
{
char temp;
char cc;
std::string str;
while (std::cin >> str) {
// n s u b => u b s n
if (str[4] == '1' || str[5] == '1') {
temp = str[2]; cc = str[3];
str[2] = str[4]; str[3] = str[5];
str[5] = temp; str[4] = cc;
}
while (str[0] != '1') {
temp = str[0]; cc = str[1];
str[0] = str[2]; str[1] = str[3];
str[3] = temp; str[2] = cc;
}
while (str[2] != '2') {
temp = str[2]; cc = str[3];
str[2] = str[4]; str[3] = str[5];
str[5] = temp; str[4] = cc;
}
if (str[4] == '4') std::cout << "left" << std::endl;
else std::cout << "right" << std::endl;
}
}