AOJ 0502
・問題リンクDice
・コメント
問題文をそのまま実装しただけですー
・ソース
import java.util.Scanner; public class P0502 { static int top = 1; static int bottom = 6; static int front = 5; static int back = 2; static int right = 3; static int left = 4; static int temp = 0; public static int north() { temp = front; front = top; top = back; back = bottom; bottom = temp; return top; } public static int south() { temp = top; top = front; front = bottom; bottom = back; back = temp; return top; } public static int east() { temp = top; top = left; left = bottom; bottom = right; right = temp; return top; } public static int west() { temp = left; left = top; top = right; right = bottom; bottom = temp; return top; } public static int right() { temp = back; back = right; right = front; front = left; left = temp; return top; } public static int left() { temp = right; right = back; back = left; left = front; front = temp; return top; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); if (n == 0) { break; } top = 1; bottom = 6; front = 5; back = 2; right = 3; left = 4; temp = 0; int sumOfTop = top; for (int i = 0; i < n; i++) { String cmd = sc.next(); if (cmd.equals("North")) { sumOfTop += north(); } else if (cmd.equals("South")) { sumOfTop += south(); } else if (cmd.equals("West")) { sumOfTop += west(); } else if (cmd.equals("East")) { sumOfTop += east(); } else if (cmd.equals("Right")) { sumOfTop += right(); } else { sumOfTop += left(); } } System.out.println(sumOfTop); } } }