Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Dice I

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

$0 \leq $ the integer assigned to a face $ \leq 100$

$0 \leq $ the length of the command $\leq 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

Solution in JAVA (judge verdict: Wrong Answer)



import java.util.Scanner;

class Diceclass {

	// declear
	static final int DICEDESIGN = 6;
    static final int TOP = 0; //?????¢ ex:1
    static final int FRONT = 1;//??£??¢ ex:2
    static final int RIGHT = 2;// ex:3 order:East
    static final int LEFT = 3;// ex:4???order:West
    static final int BACK = 4;//?£???¢ ex:5 order:North
    static final int BOTTOM = 5;// ex:6 order:South

    int[][] dice = new int[DICEDESIGN][2];

    public Diceclass(){
    	for (int i = 0; i < DICEDESIGN; i++) {
    		// [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]]
    		/*for (int j = 0; j < 3; j++) {
    			dice[i][j] = dice[i+1][j+1]; // error
			}*/
			 dice [i][0] = i+1;
			 dice[i][1] = dice [i][0];
		}
    }

	/*
	 * Sample Input
	 * 1 1 2 4 8 16 32
	 * SE
	 * Sample Output
	 * 1 8
	 */

	public Diceclass(int[] diceNum) {
		this();

		for (int i = 0; i < DICEDESIGN; i++) {
			// [[1, 1], [2, 2], [3, 4], [4, 8], [5, 16], [6, 32]]
			dice[i][1] = diceNum[i];
		}
	}

	public void orderN() {// clear

		// logic T - T ->F, B ->F, BA ->BT, T ->BA
		int[] temp = dice[TOP];
		dice[TOP] = dice[FRONT];
		dice[FRONT] = dice[BOTTOM];
		dice[BOTTOM] = dice[BACK];
		dice[BACK] = temp;
	}

	public void orderS() {// clear

		// logic BT - F -> BT, T ->F, BA -> T, BT ->BA
		int[] temp = dice[BOTTOM];
		dice[BOTTOM] = dice[FRONT];
		dice[FRONT] = dice[TOP];
		dice[TOP] = dice[BACK];
		dice[BACK] = temp;
	}

	public void orderE() {// chk

		// logic E - R ->F, L ->F, BA -> L, BA -> R
		int[] temp = dice[RIGHT];
		dice[RIGHT] = dice[FRONT];
		dice[FRONT] = dice[LEFT];
		dice[LEFT] = dice[BACK];
		dice[BACK] = temp;

	}

	public void orderW() {// chk

		// logic W - F -> L, R->F, BA->R, L -> BA
		int[] temp = dice[LEFT];
		dice[LEFT] = dice[FRONT];
		dice[FRONT] = dice[RIGHT];
		dice[RIGHT] = dice[BACK];
		dice[BACK] = temp;
	}

	public int outputTOP(int top) {
		// TOP?
		return dice[top][1];
	}

}
class Main{
	public static void main(String[] args) {

		// Operation Dice1 simulation
		Scanner sc = new Scanner(System.in);

		// dice space save
		String[] tmp = sc.nextLine().split(" ");
		int[] diceNum = new int[Diceclass.DICEDESIGN];
		for (int i = 0; i < Diceclass.DICEDESIGN; i++) {
			diceNum[i] = Integer.parseInt(tmp[i]);
		}
		Diceclass diceSpace = new Diceclass(diceNum);

		// order save
		String[] order = sc.nextLine().split("");

		// order run
		for (int i = 0; i < order.length; i++) {
			switch (order[i]) {
			case "N":
				diceSpace.orderN();
				break;
			case "S":
				diceSpace.orderS();
				break;
			case "E":
				diceSpace.orderE();
				break;
			case "W":
				diceSpace.orderS();
				break;
			}
		}
		System.out.println(diceSpace.outputTOP(diceSpace.TOP));
	}
}