【JAVA】UVA 10409 - die game

題目原文:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1350

Sample Input
1
north
3
north
east
south
0

Sample Output
5
1

題目大意:先輸入一個數字,表示要翻轉幾次,最後輸出翻轉到的骰子點數。

骰子攤開圖

程式碼

Scanner sc=new Scanner(System.in);
		
		int cases; 
		while(sc.hasNextInt() && (cases=sc.nextInt())!=0){
			
			int currPost=1;
			int N=2,W=3,S=5,E=4;
			
			for(int i=0;i<cases;i++){
				String st=sc.next();
				if(st.equals("north")){
					N=currPost;
					currPost=S;
					S=7-N;
				}else if(st.equals("south")){
					S=currPost;
					currPost=N;
					N=7-S;
				}else if(st.equals("east")){
					E=currPost;
					currPost=W;
					W=7-E;
				}else if(st.equals("west")){
					W=currPost;
					currPost=E;
					E=7-W;
				}
			}
			
			System.out.println(currPost);
		}