1082 射击比赛 (20分)

1082 射击比赛 (20分)



原题链接:传送门

一、题目:

在这里插入图片描述

二、解析:

AC代码:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * 1082 射击比赛 (20分)
 * 
 * @author: ChangSheng 
 * @date:   2020年1月3日 下午9:33:08
 */
public class Main {
	public static void main(String[] args) throws IOException {
		Reader.init(System.in);
		int N = Reader.nextInt();
		String champion = "", noob = "";
		double min = 999999.0, max = 0.0;
		for (int i = 0; i < N ; i++) {
			String name = Reader.next();
			int x = Reader.nextInt();
			int y = Reader.nextInt();
			double distance = Math.sqrt(x*x+y*y);
			if (distance < min) {
				min = distance;
				champion = name;
			}
			if (distance > max) {
				max = distance;
				noob = name;
			}
		}
		System.out.print(champion+" "+noob);
	}
}


/** 读取int和double的类 */
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** 调用这个方法来初始化reader,即InputStream*/
    static void init(InputStream input) {
        reader = new BufferedReader(new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    /** 获取下一段文本 */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
	
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}
发布了99 篇原创文章 · 获赞 105 · 访问量 9298

猜你喜欢

转载自blog.csdn.net/weixin_44034328/article/details/104080820