andy6804tw
8/15/2016 - 10:53 AM

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=30637 這提請參考這篇文章當S或W時要變成負數 http://fecbob.pixnet.net/blog/post/43546822-%5Bjav

``````import java.util.*;

public class Main {

private static double rad(double d) {
return d * Math.PI / 180.0;
}

public static double GetDistance(double lat1, double lng1, double lat2, double lng2) {
double s = 2 * Math.asin(Math.sqrt(
Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
s = Math.round(s * 10000) / 10000;
return s;
}

public static void main(String[] args) {
Scanner scn=new Scanner(System.in);
int n=scn.nextInt();
while(n--!=0){
String s1=scn.next(),s2=scn.next(),s3=scn.next(),s4=scn.next();
String c1=s1.substring(0,1),c2=s2.substring(0,1),c3=s3.substring(0,1),c4=s4.substring(0,1);
int a=Integer.parseInt(s1.substring(1)),b=Integer.parseInt(s2.substring(1)),c=Integer.parseInt(s3.substring(1)),d=Integer.parseInt(s4.substring(1));
if(c1.equals("W")||c1.equals("S")){
a=0-a;
}
if(c2.equals("W")||c2.equals("S")){
b=0-b;
}
if(c3.equals("W")||c3.equals("S")){
c=0-c;
}
if(c4.equals("W")||c4.equals("S")){
d=0-d;
}
System.out.println((int)GetDistance(b,a,d,c));
}
}
/*
題目：ITSA 47 [Problem 5] Geodesic Distance
作者：1010
時間：西元 2016 年 8 月 */
}``````