這次的題目是 UVA10409: Die Game
題目主要是骰子經過旋轉後,由上往下看的數字為多少,且1,2,3三面分別為朝上,朝北,及朝西。
#include <stdio.h>
#include <string.h>
int main(){
	int n;
	while(scanf("%d",&n)){
		if(n==0) return 0;
		int up=1,down=6,north=2,south=5,east=4,west=3; //宣告每面的數字,但其實可以優化到只宣告兩個,但在這裡先沒有喔~
		int i=0;
		for(i=0;i<n;i++){
			char act[10];
			scanf("%s",act);
			if(act[0]=='n'){ //以下為旋轉骰子的過程
				int ss = down;
				down = north;
				north = up;
				up = south;
				south = ss;
			}
			else if(act[0]=='e'){
				int ss = down;
				down = east;
				east = up;
				up = west;
				west = ss;
			}
			else if(act[0]=='s'){
				int ss = down;
				down = south;
				south = up;
				up = north;
				north = ss;
			}
			else if(act[0]=='w'){
				int ss = down;
				down = west;
				west = up;
				up = east;
				east = ss;
			} //以上為旋轉骰子的過程
		}
		printf("%d\n",up);
	}
	return 0;
}