#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_ORDER_LENGTH 100
#define NUM_DICE_FACE    6
#define END_LOOP         0

typedef unsigned char   U1;
typedef unsigned short  U2;
typedef unsigned long   U4;
typedef signed   char   S1;
typedef signed   short  S2;
typedef signed   long   S4;

struct Dice {
    U1 u1Top;
    U1 u1South;
    U1 u1East;
    U1 u1North;
    U1 u1West;
    U1 u1Bottom;
};

/********************************************************************************/
/* 関数名   | inputDiceInfo                                                     */
/* 戻り値   | 無し                                                              */
/* 備考     | 無し                                                              */
/********************************************************************************/
void inputDiceInfo(U1 *u1DiceInfo)
{
	int intInput;
    U1 u1Cnt;
    for(u1Cnt = 0; u1Cnt < NUM_DICE_FACE; u1Cnt++)
    {
        scanf("%d", &intInput);
		u1DiceInfo[u1Cnt] = intInput;
    }
}

/********************************************************************************/
/* 関数名   | inputDiceInfo                                                     */
/* 戻り値   | 無し                                                              */
/* 備考     | 無し                                                              */
/********************************************************************************/
void inputCommand(char *chCommand)
{
    scanf("%s",chCommand);
}

/********************************************************************************/
/* 関数名   | initData                                                          */
/* 戻り値   | 無し                                                              */
/* 備考     | 無し                                                              */
/********************************************************************************/
void initData(struct Dice *stDice,U1 *u1DiceInfo)
{
    U1 u1Cnt;
    U1 *u1TmpDiceNum;
    
    u1TmpDiceNum = u1DiceInfo;
    
    stDice->u1Top    = (U1)u1DiceInfo[0];
    stDice->u1South  = (U1)u1DiceInfo[1];
    stDice->u1East   = (U1)u1DiceInfo[2];
    stDice->u1West   = (U1)u1DiceInfo[3];
    stDice->u1North  = (U1)u1DiceInfo[4];
    stDice->u1Bottom = (U1)u1DiceInfo[5];
}

/********************************************************************************/
/* 関数名   | chngDice                                                          */
/* 戻り値   | 無し                                                              */
/* 備考     | 無し                                                              */
/********************************************************************************/
void chngDice(struct Dice *stDice,char chCommand)
{
    U1 u1TmpVal;
    if(chCommand == 'N')
    {
        u1TmpVal        =   stDice->u1Top;
        stDice->u1Top   =   stDice->u1South;
        stDice->u1South =   stDice->u1Bottom;
        stDice->u1Bottom=   stDice->u1North;
        stDice->u1North =   u1TmpVal;
    }
    else if(chCommand == 'S')
    {
        u1TmpVal        =   stDice->u1Top;
        stDice->u1Top   =   stDice->u1North;
        stDice->u1North =   stDice->u1Bottom;
        stDice->u1Bottom=   stDice->u1South;
        stDice->u1South =   u1TmpVal;
    }
    else if(chCommand == 'W')
    {
        u1TmpVal        =   stDice->u1Top;
        stDice->u1Top   =   stDice->u1East;
        stDice->u1East  =   stDice->u1Bottom;
        stDice->u1Bottom=   stDice->u1West;
        stDice->u1West  =   u1TmpVal;
    }
    else if(chCommand == 'E')
    {
        u1TmpVal        =   stDice->u1Top;
        stDice->u1Top   =   stDice->u1West;
        stDice->u1West  =   stDice->u1Bottom;
        stDice->u1Bottom=   stDice->u1East;
        stDice->u1East  =   u1TmpVal;
    }
    else
    {
        ;
    }
}

U1 retDiceTop(struct Dice *stDice)
{
    return stDice->u1Top;
}

void outputDiceTop(struct Dice *stDice)
{
    printf("%d\n",stDice->u1Top);
}

/********************************************************************************/
/* 関数名   | main                                                              */
/* 引数     | 無し                                                              */
/* 戻り値   | 無し                                                              */
/* 備考     | 無し                                                              */
/********************************************************************************/
int main(void)
{
    struct Dice stDice;
    U2 u2TopSum;
    U1 u1DiceInfo[NUM_DICE_FACE];
    U1 u1CommandCnt;
    char chCommand[MAX_ORDER_LENGTH + 1];

    /* 入力部 */
    inputDiceInfo(u1DiceInfo);
    inputCommand(chCommand);

    /* 制御部 */
    initData(&stDice,u1DiceInfo);
    
    u1CommandCnt = 0;

	while(chCommand[u1CommandCnt] != '\0')
    {
        chngDice(&stDice,chCommand[u1CommandCnt]);
        u1CommandCnt++;
    }
    /* 出力部 */
    outputDiceTop(&stDice);
}



Measured memory_bytes: 2148