Pascal/BAEKJOON

pascal 31312번 Water Journal (백준)

rofn123 2025. 8. 31. 01:51
var n,a,b,c,d,e:int64;
begin
read(n,a,b);d:=0;e:=0;
repeat
n-=1;
read(c);
if c=a then d:=1;
if c=b then e:=1;
until n=1;
if e+d=0 then write(-1)
else if(d=1)and(e=0)then write(b)
else if(d=0)and(e=1)then write(a)
else for n:=a to b do write(n,' ');
end.

 

풀이 : 많은 조건 분기?

 

1. 최소값, 최댓값이 입력되었다면 a~b 전부를 출력합니다.

2. 최소값만 입력되었다면 최댓값을 출력합니다.

3. 최댓값만 입력되었다면 최솟값을 출력합니다.

4. 둘 다 입력되지 않았다면 기억이 잘못된것이므로 -1 을 출력합니다.