var inp:text; count,w:byte; cart,s1:string; value:integer; x,y,d:real; procedure FindN(var value:integer); var p:byte; i:byte; tp,s:string; err:word; begin p:=pos(',',cart); if p<>0 then begin s:=copy(cart,1,p-1); delete(cart,1,p); end; if p=0 then begin s:=copy(cart,1,ord(cart[0])-1); cart:=''; end; i:=1; tp:=''; While s[i] in['0'..'9'] do begin tp:=tp+s[i]; inc(i); end; val(tp,value,err); delete(s,1,ord(tp[0])); if s='N' then w:=1; if s='NE' then w:=2; if s='E' then w:=3; if s='SE' then w:=4; if s='S' then w:=5; if s='SW' then w:=6; if s='W' then w:=7; if s='NW' then w:=8; end; begin assign(inp,'treasure.in'); reset(inp); ReadLn(inp,cart); count:=1; While cart<>'END' do begin x:=0; y:=0; While cart<>'' do begin FindN(value); case w of 1: y:=y+value; 2: begin x:=x+sin(pi/180*45)*value; y:=y+sin(pi/180*45)*value; end; 3: x:=x+value; 4: begin x:=x+sin(pi/180*45)*value; y:=y-sin(pi/180*45)*value; end; 5: y:=y-value; 6: begin x:=x-sin(pi/180*45)*value; y:=y-sin(pi/180*45)*value; end; 7: x:=x-value; 8: begin x:=x-sin(pi/180*45)*value; y:=y+sin(pi/180*45)*value; end; end; end; WriteLn('Карта #',count); WriteLn('Координаты сокровища (',x:3:3,',',y:3:3,').'); d:=sqrt(x*x+y*y); WriteLn('Расстояние до сокровища ',d:3:3,'.'); WriteLn; Inc(count); ReadLn(inp,cart); end; close(inp); end.