题目
思路
题解
package hwod;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ExplorationCave {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
int[] res = explorationCave(str);
System.out.println("(" + res[0] + "," + res[1] + ")");
}
private static int[] explorationCave(String str) {
Pattern p = Pattern.compile("\\(\\d+,\\d+\\)");
Matcher m = p.matcher(str);
int[] res = new int[]{0, 0};
while (m.find()) {
String s = m.group();
int[] location = Arrays.stream(s.substring(1, s.length() - 1).split(",")).mapToInt(Integer::parseInt).toArray();
if (location[0] > 0 && location[1] > 0
&& location[0] < 1000 && location[1] < 1000
&& location[0] * location[0] + location[1] * location[1] > res[0] * res[0] + res[1] * res[1]) {
res[0] = location[0];
res[1] = location[1];
}
}
return res;
}
}
推荐
如果你对本系列的其他题目感兴趣,可以参考华为OD机试真题及题解(JAVA),查看当前专栏更新的所有题目。