UVA 10409 Java

  1. import java.util.*;
  2. import static java.lang.System.*;
  3.  
  4. public class main{
  5. public static void main(String[] args) {
  6. Scanner sc=new Scanner(System.in);
  7. while(sc.hasNextInt())
  8. {
  9. int num = sc.nextInt();
  10. if(num == 0)
  11. break;
  12. int top = 1, n = 2, w = 3, s = 5, e = 4;
  13. for(int i = 0; i < num; i++)
  14. {
  15. String cmd = sc.next();
  16. if(cmd.equals("north"))
  17. {
  18. n = top;
  19. top = s;
  20. s = 7 - n;
  21. }
  22. else if(cmd.equals("east"))
  23. {
  24. e = top;
  25. top = w;
  26. w = 7 - e;
  27. }
  28. else if(cmd.equals("south"))
  29. {
  30. s = top;
  31. top = n;
  32. n = 7 - s;
  33. }
  34. else if(cmd.equals("west"))
  35. {
  36. w = top;
  37. top = e;
  38. e = 7 - w;
  39. }
  40. }
  41. System.out.println(top);
  42. }
  43. }
  44. };
  45.  

留言

這個網誌中的熱門文章

C# 井字遊戲