Guest User

Untitled

a guest
Mar 17th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class Main {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. String[] wheel = new String[5];
  7. wheel[1] = sc.nextLine();
  8. wheel[2] = sc.nextLine();
  9. wheel[3] = sc.nextLine();
  10. wheel[4] = sc.nextLine();
  11. int k = sc.nextInt();
  12. for (int a = 0; a < k; a++) {
  13. int[] d = new int[5];
  14. int n = sc.nextInt();
  15. d[n] = sc.nextInt();
  16. for (int b = n - 1; b >= 1; b--) {
  17. if (wheel[b].charAt(2) != wheel[b + 1].charAt(6)) {
  18. d[b] = -d[b + 1];
  19. }
  20. }
  21. for (int b = n + 1; b <= 4; b++) {
  22. if (wheel[b].charAt(6) != wheel[b - 1].charAt(2)) {
  23. d[b] = -d[b - 1];
  24. }
  25. }
  26. for (int b = 1; b <= 4; b++) {
  27. rotate(wheel, b, wheel[b], d[b]);
  28. }
  29. }
  30. int answer = 0;
  31. if (wheel[1].charAt(0) == '1') {
  32. answer += 1;
  33. }
  34. if (wheel[2].charAt(0) == '1') {
  35. answer += 2;
  36. }
  37. if (wheel[3].charAt(0) == '1') {
  38. answer += 4;
  39. }
  40. if (wheel[4].charAt(0) == '1') {
  41. answer += 8;
  42. }
  43. System.out.println(answer);
  44. sc.close();
  45. }
  46.  
  47. private static void rotate(String[] wheel, int b, String string, int i) {
  48. if (i == 1) {
  49. char c = string.charAt(7);
  50. String s = string.substring(0, 7);
  51. wheel[b] = c + s;
  52. } else if (i == -1) {
  53. char c = string.charAt(0);
  54. String s = string.substring(1, 8);
  55. wheel[b] = s + c;
  56. }
  57. }
  58. }
Add Comment
Please, Sign In to add comment