Guest User

Untitled

a guest
Oct 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. //주사위 굴리기
  2. #include <cstdio>
  3. #include <vector>
  4. using namespace std;
  5. int xx[4] = { 1,-1,0,0 };
  6. int yy[4] = { 0,0,-1,1 };
  7. int X, Y, K, a, b;
  8. int map[20][20];
  9. struct xy{
  10. int y, x;
  11. int a;//맨 위
  12. int b, c, d, e;
  13. int f;//바닥
  14. void set(int yy, int xx) {
  15. y = yy;
  16. x = xx;
  17. }
  18. void east() {
  19. int tmp = a;
  20. a = d;
  21. d = f;
  22. f = c;
  23. c = tmp;
  24. }
  25. void west() {
  26. int tmp = a;
  27. a = c;
  28. c = f;
  29. f = d;
  30. d = tmp;
  31. }
  32. void north() {
  33. int tmp = a;
  34. a = e;
  35. e = f;
  36. f = b;
  37. b = tmp;
  38. }
  39. void south() {
  40. int tmp = a;
  41. a = b;
  42. b = f;
  43. f = e;
  44. e = tmp;
  45. }
  46. void move(int dir) {
  47. x += xx[dir];
  48. y += yy[dir];
  49. if (x < 0 || y < 0 || x >= X || y >= Y) {
  50. x -= xx[dir];
  51. y -= yy[dir];
  52. return;
  53. }
  54. if (dir == 0)
  55. east();
  56. else if (dir == 1)
  57. west();
  58. else if (dir == 2)
  59. south();
  60. else
  61. north();
  62. if (map[y][x] == 0)
  63. map[y][x] = f;
  64. else {
  65. f = map[y][x];
  66. map[y][x] = 0;
  67. }
  68. printf("%d\n", a);
  69. }
  70. };
  71. xy dice;
  72. int main() {
  73. scanf("%d%d%d%d%d", &Y, &X, &a, &b, &K);
  74. dice.set(a,b);
  75. for (int i = 0; i < Y; i++) {
  76. for (int j = 0; j < X; j++) {
  77. scanf("%d", &map[i][j]);
  78. }
  79. }
  80. for (int i = 0; i < K; i++) {
  81. scanf("%d", &a);
  82. dice.move(a - 1);
  83. }
  84. return 0;
  85. }
Add Comment
Please, Sign In to add comment