题意:给出球面上两点经纬度,计算球面两点距离。输入输出比较恶心。
公式题 直接上公式就能A。
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
double a1,b1,a2,b2,d,r=6875/2.0;
char s[99];
double Dis3D(double a1,double b1,double a2,double b2)
{
return r*acos(sin(a1)*sin(a2)+cos(a1)*cos(a2)*cos(b1-b2));
}
int Get()
{
int a=0;
char c;
while((c=getchar())<'0'||c>'9');
for(;c>='0'&&c<='9';c=getchar())a=a*10+c-'0';
return a;
}
void GetA(double &a)
{
a=Get()+Get()/60.0+Get()/3600.0;
scanf("%s",s);
if(s[0]=='S'||s[0]=='W')a=-a;
a=a*acos(-1.0)/180;
}
int main()
{
while(gets(s),s[0]!='=')
{
GetA(a1),GetA(a1),GetA(b1),GetA(a2),GetA(b2);
d=Dis3D(a1,b1,a2,b2);
printf("The distance to the iceberg: %.2lf miles.\n",d);
if(floor(d+0.005)<100)puts("DANGER!");
gets(s);
}
return 0;
}