⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3390978_ac_313ms_2948k.java

📁 北大大牛代码 1240道题的原代码 超级权威
💻 JAVA
字号:
import java.util.*;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	final double c = Math.sqrt(2.0);
	
	private void run() {
		Scanner in = new Scanner(System.in);
		String str;
		StringTokenizer st;
		double x, y;
		int cas;

		cas = 0;
		while (true) {
			str = in.next();
			if (str.equals("END")) {
				break;
			}
			cas++;
			st = new StringTokenizer(str, ",.");
			x = y = 0.0;
			while (st.hasMoreTokens()) {
				String tmp = st.nextToken();
				int i;
				for (i = 0; Character.isDigit(tmp.charAt(i)) ; i++);
				double len = Double.parseDouble(tmp.substring(0, i));
				tmp = tmp.substring(i);
				if (tmp.equals("N"))
				{
					y += len;
					continue;
				}
				if (tmp.equals("S"))
				{
					y -= len;
					continue;
				}
				if (tmp.equals("E"))
				{
					x += len;
					continue;
				}
				if (tmp.equals("W"))
				{
					x -= len;
					continue;
				}
				len /= c;
				if (tmp.equals("NE"))
				{
					x += len;
					y += len;
					continue;
				}
				if (tmp.equals("SE"))
				{
					x += len;
					y -= len;
					continue;
				}
				if (tmp.equals("SW"))
				{
					x -= len;
					y -= len;
					continue;
				}
				if (tmp.equals("NW"))
				{
					x -= len;
					y += len;
					continue;
				}
			}
			System.out.println("Map #" + cas);
			if (Math.abs(x) < 1e-6)		x = 0;
			if (Math.abs(y) < 1e-6)		y = 0;
			System.out.format("The treasure is located at (%.3f,%.3f).\n", x, y);
			System.out.format("The distance to the treasure is %.3f.\n\n", Math.hypot(x, y));
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -