📄 3390976_wa.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);
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 + -