我是靠谱客的博主 甜蜜果汁,最近开发中收集的这篇文章主要介绍翻转骰子(模拟),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

题目链接点击打开链接

竟然是日本的一个大学的网站 会津大学,学习了

Write a program to simulate rolling a dice, which can be constructed by the following net.






As shown in the figures, each face is identified by a different label from 1 to 6.

Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.

Input

In the first line, six integers assigned to faces are given in ascending order of their corresponding labels.

In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.

Output

Print the integer which appears on the top face after the simulation.

Constraints

  • 00≤ the integer assigned to a face 100≤100
  • 00≤ the length of the command 100≤100

Sample Input 1

1 2 4 8 16 32
SE

Sample Output 1

8

You are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face labeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction S and then to the direction E, you can see 8 on the top face.



Sample Input 2

1 2 4 8 16 32
EESWN

Sample Output 2

32    
题意:就是重定义骰子,然后根据指示输出最后朝上的数字是什么

PY写的,先马住,日后再分析OTZ

r={'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3)}
d=input().split()
for x in input():
    d=[d[y]for y in r[x]]
print(d[0])

别人的PY看不懂,自己用c++实现了,就是一个模拟,记录下当前骰子的状态,并不断更新

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int s[7];
int k;
string c;
void  f(int k)
{
    if(c[k]=='S')
    {
       int t=s[1];
       s[1]=s[3];
       s[3]=s[6];
       s[6]=s[2];
       s[2]=t;
    }
      if(c[k]=='N')
    {
       int t=s[3];
       s[3]=s[1];
       s[1]=s[2];
       s[2]=s[6];
       s[6]=t;
    }
        if(c[k]=='W')
    {
       int t=s[1];
       s[1]=s[5];
       s[5]=s[6];
       s[6]=s[4];
       s[4]=t;
    }
          if(c[k]=='E')
    {
       int t=s[1];
       s[1]=s[4];
       s[4]=s[6];
       s[6]=s[5];
       s[5]=t;
    }
}
int main()
{
        cin>>s[1];
        cin>>s[2];
        cin>>s[5];
        cin>>s[4];
        cin>>s[3];
        cin>>s[6];

//  for(int i=1;i<=6;i++)  cout<<s[i]<<' ';
    cin>>c;
    for(int i=0;i<c.size();i++)
    {
        f(i);
    }
    cout<<s[1]<<endl;
    return 0;
}

最后

以上就是甜蜜果汁为你收集整理的翻转骰子(模拟)的全部内容,希望文章能够帮你解决翻转骰子(模拟)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部