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 victory.

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, 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 explicitly specify anything but tell you the golden rule: the sum of the numbers on any pair of opposite faces is always seven.

Your program should 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 direction and the rotation angle is 90 degrees. Other commands also tumble the die accordingly to their own directions. Your program should calculate the number finally shown on the top after performing 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 includes a command that is one of northeastsouth, 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
1
#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;
}

10409 - Die Game的更多相关文章

  1. No zuo no die:DDD 应对具体业务场景,Domain Model 重新设计

    写在前面 上联:no zuo no die why you try 下联:no try no high give me five 横批: let it go上联:no zuo no die why y ...

  2. Also unsere eigene Christian Louboutin Webshop bietet die überragende Christian Louboutin Schuhe uk schiebt zusammen mit kostengünstigen Wert

    www.heelschuhe.de, Es ist wirklich eine der Frauen erfordern immer interessant und auch Louboutin Pu ...

  3. php的exit和die

    首先, 两者是相等的: exit is equivalent to die; 其次, 都是语言构造器, language construct. 不是函数! 后面的内容用括号括起来只是为了方便... 用 ...

  4. IE6 Must Die

    最近 Twitter 上很多人在推一个名为 IE6 Must Die 的活动, 参与的朋友可以通过头像转换服务在自己的头像上加上一个禁止 IE6 的图标, 很是拉风. Internet Explore ...

  5. (译)开发优秀的虚拟现实体验:从开发I Expect You to Die中总结的六个要点

    这篇文章是我从网上找来的,我觉得他非常详细的解释了VR发展的需求和必要.我认为通过这篇文章可以让大家了解VR. 译者写在最前: 来到追光动画有好几个月了,抱歉这段时间也没有什么文章与大家分享,我现在在 ...

  6. @错误抑制运算符和or die()

    1.错误抑制运算符可在任何表达式前使用,PHP支持一个错误抑制运算符@.当将其放置在一个PHP表达式之前,则该表达式可能产生的任何错误信息都被忽略掉.@运算符只对表达式有效. 2.or die() 当 ...

  7. return,exit,die

    return:代表退出某个函数,但是函数体外的语句仍然需要执行. exit:退出程序,但是不从内存中卸载,exit其实也是可以输出语句的,加一个括号即可. die:退出程序,并且从内存中卸载.

  8. UVa657 The die is cast

    // 题意:给一个图案,其中'.'表示背景,非'.'字符组成的连通块为筛子.每个筛子里又包含两种字符,其中'X'组成的连通块表示筛子上的点 // 统计每个筛子里有多少个"X"连通块 ...

  9. Codeforces Beta Round #51 C. Pie or die 博弈论找规律 有趣的题~

    C. Pie or die Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem/ ...

随机推荐

  1. PHP漏洞全解(一)-PHP网站的安全性问题

    本文主要介绍针对PHP网站常见的攻击方式,包括常见的sql注入,跨站等攻击类型.同时介绍了PHP的几个重要参数设置.后面的系列文章将站在攻击者的角度,为你揭开PHP安全问题,同时提供相应应对方案. 针 ...

  2. 释放SQL Server占用的内存

    由于Sql Server对于系统内存的管理策略是有多少占多少,除非系统内存不够用了(大约到剩余内存为4M左右),Sql Server才会释放一点点内存.所以很多时候,我们会发现运行Sql Server ...

  3. 133. Clone Graph

    题目: Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. ...

  4. Structs 原理图

    Struts开源架构很好的实现了MVC模式,MVC即Model-View-Controller的缩写,是一种常用的设计模式.MVC 减弱了业务逻辑接口和数据接口之间的耦合,以及让视图层更富于变化.MV ...

  5. java比较器Comparable接口和Comaprator接口

    Comparable故名思意是比较,意思就是做比较的,然后进行排序. 1.什么是comparable接口 此接口强行对实现它的每个类的对象进行整体排序.此排序被称为该类的自然排序 ,类的 compar ...

  6. 测试ODBC与OLE

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data. ...

  7. bzoj2506

    不知道该给这题贴什么标签了,但是这是一道好题1.注意这道题的询问是满足区间减法的,我们可以把一个询问拆成两个询问离线搞搞,这个思想在后面会见到2.分类的思想,这道题的求相同余数看似很烦,实际上我们发现 ...

  8. apache虚拟主机的设置

    方法一: 首先打开apache中conf下的http.conf文件打开虚拟主机的注释:如下去掉第二行前面的#即可 # Virtual hosts# Include conf/extra/httpd-v ...

  9. SharePoint2010主题和样式揭秘

    转:http://www.cnblogs.com/Ryu666/archive/2011/07/28/2119652.html 好久好久没写技术博客了,差点以为技术已经离我远去.但鱼离不开水,我怎能把 ...

  10. 一步步写STM32 OS【四】OS基本框架

    一.上篇回顾 上一篇文章中,我们完成了两个任务使用PendSV实现了互相切换的功能,下面我们接着其思路往下做.这次我们完成OS基本框架,即实现一个非抢占式(已经调度的进程执行完成,然后根据优先级调度等 ...