Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- // Battle Town 9:52-11:18
- static Scanner sc = new Scanner(System.in);
- static void solve(){
- int[] dx = {-1,0,1,0}; int[] dy={0,1,0,-1};
- int x = sc.nextInt(); int y = sc.nextInt();
- String[] sen={"^",">","v","<"};
- String[] zyo={"U","R","D","L"};
- StringBuffer[] field = new StringBuffer[x];
- int xx=0;int yy=0;int d=0;
- for(int a=0;a<x;a++){
- String te = sc.next();
- for(int b=0;b<4;b++){
- if(te.indexOf(sen[b])!=-1){
- xx=a;yy=te.indexOf(sen[b]);d=b;
- te = te.replace(sen[b].charAt(0),'.');
- break;
- }
- }
- field[a] = new StringBuffer(te);
- }
- int len = sc.nextInt();
- String com = sc.next();
- for(int a=0;a<len;a++){
- if(com.charAt(a)=='S'){
- int tx = xx+dx[d]; int ty = yy+dy[d];
- while(tx>=0&&tx<x&&ty>=0&&ty<y){
- if(field[tx].charAt(ty)=='#') break;
- else if(field[tx].charAt(ty)=='*'){
- field[tx].replace(ty,ty+1,".");
- break;
- }
- tx += dx[d]; ty += dy[d];
- }
- }else{
- for(int b=0;b<4;b++){
- if(com.charAt(a)==zyo[b].charAt(0)){
- d = b;
- if(xx+dx[d]>=0&&xx+dx[d]<x&&yy+dy[d]>=0&&yy+dy[d]<y){
- xx += dx[d]; yy +=dy[d];
- if(field[xx].charAt(yy)!='.'){
- xx -= dx[d]; yy -=dy[d];
- }
- }
- }
- }
- }
- }
- field[xx].replace(yy,yy+1,sen[d]); //最後の戦車位置
- for(int a=0;a<x;a++) System.out.println(field[a].substring(0));
- }
- public static void main(String[] args) {
- int n = sc.nextInt();
- for(int a=0;a<n-1;a++){
- solve();
- System.out.println();
- }
- solve(); //最後の出力後の改行はないので…
- }
- }
Add Comment
Please, Sign In to add comment