10409-Die Game

Source: Internet
Author: User

Problem G: Die Game
Life is not easy. Sometimes it is beyond your control. Now, as contestants of acm icpc, you might be just tasting the bitter of life. But don't worry! Do not look only on the dark side of life, but look also on the bright side. Life may be an enjoyable game of chance, like throwing dice. Do or die! Then, at last, you might be able to find the route to Vicente.

This problem comes from a game using a die. By the way, do you know a die? It has nothing to do with "death. "A die is a cubic object with six faces, each of which represents a different number from one to six and is marked with the corresponding number of spots. since it is usually used in pair, "a die" is a rarely used word. you might have heard a famous phrase "the die is cast," though.

When a game starts, a die stands still on a flat table. during the game, the die is tumbled in all directions by the dealer. you will win the game if you can predict the number seen on the top face at the time when the die stops tumbling.

Now you are requested to write a program that simulates the rolling of a die. for simplicity, we assume that the die neither slips nor jumps but just rolls on the table in four directions ctions, that is, north, east, south, and west. at the beginning of every game, the dealer puts the die at the center of the table and adjusts its direction so that the numbers one, two, and three are seen on the top, north, and west faces, respectively. for the other three faces, we do not explain icitly specify anything but tell you the golden rule: the sum of the numbers on any pair of opposite faces is always seven.

Your program shocould accept a sequence of commands, each of which is either "north", "east", "south", or "west ". A "north" command tumbles the die down to north, that is, the top face becomes the new north, the north becomes the new bottom, and so on. more precisely, the die is rotated around its north bottom edge to the north ction and the rotation angle is 90 degrees. other commands also tumble the die accordingly to their own directions. your program shocould calculate the number finally shown on the top after loading the commands in the sequence. note that the table is sufficiently large and the die never falls off during the game.



Input
The input consists of one or more command sequences, each of which corresponds to a single game. the first line of a command sequence contains a positive integer, representing the number of the following command lines in the sequence. you may assume that this number is less than or equal to 1024. A line containing a zero indicates the end of the input. each command line between des a command that is one of north, east, south, and west. you may assume that no white space occurs in any lines.

Output
For each command sequence, output one line containing solely the number on the top face at the time when the game is finished.

Sample Input
1
North
3
North
East
South
0
Output for the Sample Input
5

#include<stdio.h>int main(){int N,i;char x[10];while(scanf("%d",&N)&&N){int n=2,w=3,e=4,s=5,t=1,b=6;getchar();for(i=0;i<N;i++){int n1,b1,t1,s1,w1,e1;gets(x);if(x[0]=='n'){n1=t;b1=n;w1=w;e1=e;s1=7-n1;t1=7-b1;}else if(x[0]=='s'){s1=t;b1=s;w1=w;e1=e;n1=7-s1;t1=7-b1;}else if(x[0]=='w'){w1=t;b1=w;n1=n;s1=s;e1=7-w1;t1=7-b1;}else if(x[0]=='e'){e1=t;b1=e;n1=n;s1=s;w1=7-e1;t1=7-b1;}n=n1;b=b1;t=t1;s=s1;w=w1;e=e1;}printf("%d\n",t);}return 0;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.