fork download
  1. //http://w...content-available-to-author-only...m.br/meublog/competir/robo-colecionador-maratona2010/
  2. //https://w...content-available-to-author-only...m.br/judge/problems/view/1121
  3.  
  4. #include<stdio.h>
  5. struct pos {
  6. int x;
  7. int y;
  8. int prox_x;
  9. int prox_y;
  10. }pos;
  11.  
  12. int main (void) {
  13. int L, C, S;
  14. while (scanf("%d %d %d", &L, &C, &S)&&L!=0) {
  15. int i, j, fig=0;
  16. char tab[L][C], cmd[S+1];
  17. for(i=0; i<L; i++) {
  18. for(j=0; j<C; j++) {
  19. tab[i][j]=getchar();
  20. if(tab[i][j]!='.'&&tab[i][j]!='*'&&tab[i][j]!='#') {
  21. pos.x=i;
  22. pos.y=j;
  23. switch (tab[i][j]) {
  24. case 'N':
  25. pos.prox_x=i-1;
  26. pos.prox_y=j;
  27. break;
  28. case 'S':
  29. pos.prox_x=i+1;
  30. pos.prox_y=j;
  31. break;
  32. case 'L':
  33. pos.prox_x=i;
  34. pos.prox_y=j+1;
  35. break;
  36. case 'O':
  37. pos.prox_x=i;
  38. pos.prox_y=j-1;
  39. break;
  40. }
  41. }
  42. }
  43. }
  44. scanf("%s", cmd);
  45. for (i=0; i<S; i++) {
  46. switch (cmd[i]) {
  47. case 'D':
  48. if (pos.prox_y==pos.y) {
  49. if (pos.prox_x>pos.x) {
  50. pos.prox_x=pos.x;
  51. pos.prox_y=pos.y-1;
  52. }
  53. else {
  54. pos.prox_x=pos.x;
  55. pos.prox_y=pos.y+1;
  56. }
  57. }
  58. else {
  59. if (pos.prox_y>pos.y) {
  60. pos.prox_y=pos.y;
  61. pos.prox_x=pos.x+1;
  62. }
  63. else {
  64. pos.prox_y=pos.y;
  65. pos.prox_x=pos.x-1;
  66. }
  67. }
  68. break;
  69. case 'E':
  70. if (pos.prox_x==pos.x) {
  71. if (pos.prox_y>pos.y) {
  72. pos.prox_y=pos.y;
  73. pos.prox_x=pos.x-1;
  74. }
  75. else {
  76. pos.prox_y=pos.y;
  77. pos.prox_x=pos.x+1;
  78. }
  79. }
  80. else {
  81. if (pos.prox_x>pos.x) {
  82. pos.prox_x=pos.x;
  83. pos.prox_y=pos.y+1;
  84. }
  85. else {
  86. pos.prox_x=pos.x;
  87. pos.prox_y=pos.y-1;
  88. }
  89. }
  90. break;
  91. case 'F':
  92. if (tab[pos.prox_x][pos.prox_y]!='#'&&(pos.prox_x<L&&pos.prox_x>-1)&&(pos.prox_y<C&&pos.prox_y>-1)) {
  93. if (tab[pos.prox_x][pos.prox_y]=='*') {
  94. tab[pos.prox_x][pos.prox_y]='.';
  95. fig++;
  96. }
  97. if (pos.prox_y==pos.y) {
  98. if (pos.prox_x>pos.x) {
  99. pos.x=pos.prox_x;
  100. pos.prox_x++;
  101.  
  102. }
  103. else {
  104. pos.x=pos.prox_x;
  105. pos.prox_x--;
  106. }
  107. }
  108. else {
  109. if (pos.prox_y>pos.y) {
  110. pos.y=pos.prox_y;
  111. pos.prox_y++;
  112.  
  113. }
  114. else {
  115. pos.y=pos.prox_y;
  116. pos.prox_y--;
  117. }
  118. }
  119. }
  120. break;
  121. }
  122.  
  123. }
  124. printf("%d\n", fig);
  125. }
  126. return 0;
  127. }
Success #stdin #stdout 0s 5440KB
stdin
3 3 2
***
*N*
***
DE
4 4 5
...#
*#O.
*.*.
*.#.
FFEFF
10 10 20
....*.....
.......*..
.....*....
..*.#.....
...#N.*..*
...*......
..........
..........
..........
..........
FDFFFFFFEEFFFFFFEFDF
0 0 0
stdout
0
1
3