Surface:
You are now asked to write a program to simulate the roll of the dice. The dice do not slide or beat, only on the table in the four-direction scrolling, that is, east. At the beginning of each game, the player makes the dice with a nominal value of one, north, west. The relative sides of the dice are all 7. Your program can accept a series of input commands, the command content is north,south,east,west. As North, the dice roll northward, the north to the bottom and the top to the north. The rolling angle is 90 °. Your program must calculate the last digit of the dice.
Input:
The input consists of a sequence of commands, each corresponding to the beginning of a new game, whose first line is an integer n (0<n<=1024), which represents the number of command bars, followed by n behavior commands. Entering 0 indicates the end of the input.
Output:
For each command sequence, output the last digit of the dice.
Input Example:
1
North
3
North
East
South
0
Output Example:
5
1
Idea: Record the face value (a,b,c) on three sides of the upper north West after each scroll.
Code:
1#include <fstream>2#include <iostream>3#include <algorithm>4#include <cstdio>5#include <cstring>6#include <cmath>7#include <cstdlib>8 9 using namespacestd;Ten One #definePI ACOs (-1.0) A #defineEPS 1e-10 - #defineLLL __int64 - #definell Long Long the #defineINF 0x7fffffff - - intN; - Chars[Ten]; + - intMain () + { A //freopen ("d:\\input.in", "R", stdin); at //freopen ("D:\\output.out", "w", stdout); - while(SCANF ("%d",&N), N) { - GetChar (); - intA=1, b=2, c=3, AA,BB,CC; - for(intI=0; i<n;i++){ - gets (s); in if(s[0]=='N'){ -Aa=7-b; todb{A; +Cc=C; -}Else if(s[0]=='s'){ theAa=b; *bb=7-A; $Cc=C;Panax Notoginseng}Else if(s[0]=='W'){ -Aa=7-C; thebb=b; +Cc=A; A}Else{ theAa=C; +bb=b; -Cc=7-A; $ } $A=AA; -b=BB; -C=cc; the } -printf"%d\n", a);Wuyi } the return 0; -}
View Code
Dice Game problem