Input is disgusting.
First the latitude and longitude of the time of the second conversion into degrees, and then according to things, south latitude to take the sign. Then according to the two-point distance formula of the ball.
The final attention to the precision to take a larger
#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;}
POJ 2354 Titanic