输入好恶心
先把经纬度的时分秒转换成度,再根据东西经,南北纬取正负号。然后根据球上两点距离公式求。
最后注意精度要取大一点
#include<stdio.h> #include<math.h> const double pi=acos(-1.0); const double eps=1e-5; int main(){ #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif // ONLINE_JUDGE double s1[3],s2[3]; int n,a; char c1,c2,c3; char st[10],s[100]; for(int i=0;i<9;i++) scanf("%s",s); scanf("%lf^%lf'%lf\" %s",&s1[0],&s1[1],&s1[2],st); scanf("%s",s); double a1,a2,b1,b2; a1=s1[0]+s1[1]/60+s1[2]/3600; if(st[0]=='S') a1=-a1; scanf("%lf^%lf'%lf\" %s.",&s1[0],&s1[1],&s1[2],st); //printf("%lf %lf %lf",s1[0],s1[1],s1[2]); b1=s1[0]+s1[1]/60+s1[2]/3600; if(st[0]=='W') b1=-b1; for(int i=0;i<5;i++) scanf("%s",s); scanf("%lf^%lf'%lf\" %s",&s1[0],&s1[1],&s1[2],st); a2=s1[0]+s1[1]/60+s1[2]/3600; if(st[0]=='S') a2=-a2; scanf("%s",s); scanf("%lf^%lf'%lf\" %s",&s1[0],&s1[1],&s1[2],st); b2=s1[0]+s1[1]/60+s1[2]/3600; if(st[0]=='W') b2=-b2; scanf("%s",s); a1=a1*pi/180;a2=a2*pi/180;b1=b1*pi/180;b2=b2*pi/180; double theta,ans; theta=acos(cos(a1)*cos(a2)*cos(b1-b2)+sin(a1)*sin(a2)); ans=6875*0.5*theta; //printf("%f",theta); printf("The distance to the iceberg: %.2f miles.\n",ans); if(ans<100-0.005) printf("DANGER!\n"); return 0; }
时间: 2024-11-07 02:32:35