我是靠谱客的博主 甜蜜果汁,这篇文章主要介绍翻转骰子(模拟),现在分享给大家,希望可以做个参考。

题目链接点击打开链接

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

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
1 2 4 8 16 32 SE

Sample Output 1

复制代码
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
1 2 4 8 16 32 EESWN

Sample Output 2

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

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

复制代码
1
2
3
4
5
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++实现了,就是一个模拟,记录下当前骰子的状态,并不断更新

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#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; }

最后

以上就是甜蜜果汁最近收集整理的关于翻转骰子(模拟)的全部内容,更多相关翻转骰子(模拟)内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部