Could anybody help me with my code?
What's wrong here? All the formulas are abviously correct,
but wwhy do I get WA?
By the way, in some discussions on this problem the author
(s) Li,Yi had the same problem, and somebody said "try :'if
way < 99.95 then ...", but this doesn't work with my
program as well.
Program Titanic;
Const di=6875; r=di/2;
Var u1,u2,u3,v1,v2,v3:Longint;
a,b:Extended;
x1,y1,z1,x2,y2,z2:Extended;
c:Char;
s:String;
d1,d2,d3:Extended;
cs,sn,al:Extended;
Function StrToInt(s:String):Longint;
Var Cod:Integer;
v:Longint;
Begin
Val(s,v,Cod);
StrToInt:=v;
End;
Function RR(st:Char):String;
Var s:String;
c:Char;
Begin
s:='';
Repeat
Read(c);
If c In ['0'..'9'] Then
s:=s+c;
Until c=st;
RR:=s;
End;
Function D(x1,y1,z1,x2,y2,z2:Extended):Extended;
Begin
D:=Sqrt(Sqr(x1-x2)+Sqr(y1-y2)+Sqr(z1-z2));
End;
Function SSin(a:Extended):Extended;
Begin
SSin:=sin(a/180*Pi);
End;
Function CCos(a:Extended):Extended;
Begin
CCos:=cos(a/180*Pi);
End;
Begin
While Not Eof Do Begin
Readln;
Readln;
Readln;
u1:=StrToInt(RR('^'));
u2:=StrToInt(RR(''''));
u3:=StrToInt(RR('"'));
Readln(s);
If Pos('N',s)>0 Then Begin
u1:=-u1;
u2:=-u2;
u3:=-u3;
End;
v1:=StrToInt(RR('^'));
v2:=StrToInt(RR(''''));
v3:=StrToInt(RR('"'));
Readln(s);
If Pos('W',s)>0 Then Begin
v1:=-v1;
v2:=-v2;
v3:=-v3;
End;
a:=u1+u2/60+u3/60/60;
{ a:=90-Abs(a);}
b:=v1+v2/60+v3/60/60;
x1:=ccos(a)*ccos(b);
y1:=ccos(a)*ssin(b);
z1:=ssin(a);
Readln;
u1:=StrToInt(RR('^'));
u2:=StrToInt(RR(''''));
u3:=StrToInt(RR('"'));
Readln(s);
If Pos('N',s)>0 Then Begin
u1:=-u1;
u2:=-u2;
u3:=-u3;
End;
v1:=StrToInt(RR('^'));
v2:=StrToInt(RR(''''));
v3:=StrToInt(RR('"'));
Readln(s);
If Pos('W',s)>0 Then Begin
v1:=-v1;
v2:=-v2;
v3:=-v3;
End;
a:=u1+u2/60+u3/60/60;
{ a:=90-Abs(a);}
b:=v1+v2/60+v3/60/60;
x2:=ccos(a)*ccos(b);
y2:=ccos(a)*ssin(b);
z2:=ssin(a);
d1:=D(0,0,0,x1,y1,z1);
d2:=D(0,0,0,x2,y2,z2);
d3:=D(x2,y2,z2,x1,y1,z1);
cs:=(d1*d1+d2*d2-d3*d3)/(2*d1*d2);
sn:=Sqrt(Abs(1-cs*cs));
If cs=0 Then
al:=Pi/2
Else
al:=Arctan(sn/cs);
If cs<0 Then
al:=al+Pi;
Writeln('The distance to the iceberg: ',al*r:0:2,'
miles.');
If al*r<100 Then
Writeln('DANGER!');
Readln;
End;
End.