Guest User

Untitled

a guest
Oct 16th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. // Battle Town 9:52-11:18
  5. static Scanner sc = new Scanner(System.in);
  6.  
  7. static void solve(){
  8. int[] dx = {-1,0,1,0}; int[] dy={0,1,0,-1};
  9. int x = sc.nextInt(); int y = sc.nextInt();
  10. String[] sen={"^",">","v","<"};
  11. String[] zyo={"U","R","D","L"};
  12. StringBuffer[] field = new StringBuffer[x];
  13. int xx=0;int yy=0;int d=0;
  14. for(int a=0;a<x;a++){
  15. String te = sc.next();
  16. for(int b=0;b<4;b++){
  17. if(te.indexOf(sen[b])!=-1){
  18. xx=a;yy=te.indexOf(sen[b]);d=b;
  19. te = te.replace(sen[b].charAt(0),'.');
  20. break;
  21. }
  22. }
  23. field[a] = new StringBuffer(te);
  24. }
  25.  
  26. int len = sc.nextInt();
  27. String com = sc.next();
  28. for(int a=0;a<len;a++){
  29. if(com.charAt(a)=='S'){
  30. int tx = xx+dx[d]; int ty = yy+dy[d];
  31. while(tx>=0&&tx<x&&ty>=0&&ty<y){
  32. if(field[tx].charAt(ty)=='#') break;
  33. else if(field[tx].charAt(ty)=='*'){
  34. field[tx].replace(ty,ty+1,".");
  35. break;
  36. }
  37. tx += dx[d]; ty += dy[d];
  38. }
  39. }else{
  40. for(int b=0;b<4;b++){
  41. if(com.charAt(a)==zyo[b].charAt(0)){
  42. d = b;
  43. if(xx+dx[d]>=0&&xx+dx[d]<x&&yy+dy[d]>=0&&yy+dy[d]<y){
  44. xx += dx[d]; yy +=dy[d];
  45. if(field[xx].charAt(yy)!='.'){
  46. xx -= dx[d]; yy -=dy[d];
  47. }
  48. }
  49. }
  50. }
  51. }
  52. }
  53.  
  54. field[xx].replace(yy,yy+1,sen[d]); //最後の戦車位置
  55. for(int a=0;a<x;a++) System.out.println(field[a].substring(0));
  56. }
  57. public static void main(String[] args) {
  58. int n = sc.nextInt();
  59. for(int a=0;a<n-1;a++){
  60. solve();
  61. System.out.println();
  62. }
  63. solve(); //最後の出力後の改行はないので…
  64. }
  65.  
  66. }
Add Comment
Please, Sign In to add comment