Pascal/BAEKJOON

pascal 15079번 Arggggggh! (백준)

rofn123 2025. 8. 31. 01:51
uses math;
var s:string;x,y,c,a,b:real;n,m:int64;
begin
readln(n,x,y);
repeat
n-=1;
if n=0 then break;
readln(s);
m:=length(s);c:=1;a:=0;
while s[m]<>' 'do begin
 a+=c*(ord(s[m])-48);
 m-=1;
 c*=10;
end;

b:=a/sqrt(2);

if s[1]='N'then begin
 if s[2]='E'then begin x+=b;y+=b;end
 else if s[2]='W'then begin x-=b;y+=b;end
 else y+=a;
end
else if s[1]='S'then begin
 if s[2]='E'then begin x+=b;y-=b;end
 else if s[2]='W'then begin x-=b;y-=b;end
 else y-=a;
end
else if s[1]='W'then x-=a
else if s[1]='E'then x+=a;
until 0=1;
writeln(x:0:8,' ',y:0:8);
end.

 

풀이 : 많은 조건 분기

 

1. n(정수형)과 좌표값들을 (실수형) 으로 입력받습니다.

2. 문자열을 입력받은 후, 여기서 이동거리를 실수형 변수에 변환해서 집어넣습니다.

3. N,W,S.E 의 경우 입력받은 거리 만큼 좌표를 이동시키고, NE,NS,WS,SE 의 경우 (입력받은거리/2^(0.5)) 만큼 두 개의 좌표를 이동시킵니다.

 

주의 : n=1 인 경우 좌표입력받은 그대로 출력하시면 됩니다.