UVA10409




Sample Input

1
north
3
north
east
south
0

Sample Output

5
1

大意:在一張很大的桌子上,骰一顆骰子,骰子的頂端是1點,前方是2點,左方是3點,
給幾個轉動的方向,求最後在頂端的點數是多少(每一面與他的對面總合一定是7 
EX:點數1的對面一定是6)

解法: 模擬題


import java.util.Scanner;

public class UVA10409 {

 public static void main(String[] args) {

  Scanner sc = new Scanner(System.in);

  while (sc.hasNext()) {

   int count = Integer.parseInt(sc.nextLine());

   if (count == 0)
    break;

   int top = 1, north = 2, west = 3;

   int temp = 0;

   for (int i = 0; i < count; i++) {

    String s = sc.nextLine();

    switch (s) {

    // temp = top(replace all repeat)
    case ("north"): {

     temp = top;
     top = 7 - north;
     north = temp;
     break;

    }
    case ("east"): {

     temp = top;
     top = west;
     west = 7 - temp;
     break;

    }
    case ("south"): {

     temp = top;
     top = north;
     north = 7 - temp;
     break;

    }
    case ("west"): {

     temp = top;
     top = 7 - west;
     west = temp;
     break;

    }

    }

   }
   System.out.println(top);

  }

  sc.close();
 }

}