最远足迹

标题:最远足迹 | 时间限制:1秒 | 内存限制:32768K | 语言限制:不限
某探险队负责对地下洞穴进行探险。探险队成员在进行探险任务时,随身携带的记录器会不定期地记录自身的坐标,但在记录的间隙中也会记录其他数据。探索工作结束后,探险队需要获取到某成员在探险过程中相对于探险队总部的最远的足迹位置。

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        System.out.println(test(s));
    }

    public static String test(String s){
        if(s == null || s == ""){
            return null;
        }
        List<String> subList = extractMessage(s);
        int i = 0;
        String rs = "";
        for(String s1 : subList){
            if(mes1(s1) > i){
                i = mes1(s1);
                rs = s1;
            }
        }
        if(i == 0){
            return "(0,0)";
        }
        return "(" + rs + ")";
    }

    public static int mes1(String s){
        String[] strings = s.split(",");
        if(strings[0].startsWith("0") || strings[1].startsWith("0")){
            return 0;
        }
        int a = Integer.valueOf(strings[0]);
        int b = Integer.valueOf(strings[1]);
        if(!(a > 0 && a <1000)){
            return 0;
        }
        if(!(b > 0 && b <1000)){
            return 0;
        }
        return a*a + b*b;
    }

    public static List<String> extractMessage(String msg) {

        List<String> list = new ArrayList<String>();
        int start = 0;
        int startFlag = 0;
        int endFlag = 0;
        for (int i = 0; i < msg.length(); i++) {
            if (msg.charAt(i) == '(') {
                startFlag++;
                if (startFlag == endFlag + 1) {
                    start = i;
                }
            } else if (msg.charAt(i) == ')') {
                endFlag++;
                if (endFlag == startFlag) {
                    list.add(msg.substring(start + 1, i));
                }
            }
        }
        return list;
    }
}


全部评论

相关推荐

迷茫的大四🐶:干脆大厂搞个收费培训得了,这样就人均大厂了
点赞 评论 收藏
分享
10-13 16:58
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
3
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务