Created
August 29, 2019 05:27
-
-
Save zeraf29/13c456c75e00e1625f0e1f919215fa9b to your computer and use it in GitHub Desktop.
BotClean - while문 및 subString 사용
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
import java.text.*; | |
import java.math.*; | |
import java.util.regex.*; | |
public class Solution { | |
static void next_move(int posr, int posc, String[] board){ | |
//add logic here | |
int targetX = 0, targetY = 0, tempX = 0, gap = 10, i=0; | |
while(i<board.length) { | |
if(board[i].indexOf('d')>-1) { | |
tempX = board[i].indexOf('d'); | |
if(Math.abs(posc-tempX)+Math.abs(posr-i)<gap ) { | |
gap = Math.abs(posc-tempX)+Math.abs(posr-i); | |
targetX = tempX; | |
targetY = i; | |
} | |
board[i] = board[i].substring(0, tempX)+'-'+(tempX<4?board[i].substring(tempX+1):""); | |
}else | |
i++; | |
} | |
if(posc==targetX && posr==targetY) { | |
System.out.println("CLEAN"); | |
}else if(posc-targetX>0) { | |
System.out.println("LEFT"); | |
}else if(posc-targetX<0) { | |
System.out.println("RIGHT"); | |
}else if(posr-targetY>0) { | |
System.out.println("UP"); | |
}else if(posr-targetY<0) { | |
System.out.println("DOWN"); | |
} | |
} | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
int [] pos = new int[2]; | |
String board[] = new String[5]; | |
for(int i=0;i<2;i++) pos[i] = in.nextInt(); | |
for(int i=0;i<5;i++) board[i] = in.next(); | |
next_move(pos[0], pos[1], board); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
문제내용> https://www.hackerrank.com/challenges/botclean
배경이론-맨하탄 거리/유클리디안 거리 > https://vsdevelop.tistory.com/2
while 및 substring을 통한 기존 발견된 d 제거 방법을 활용