티스토리 뷰

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 을 출력합니다.

'Pascal > BAEKJOON' 카테고리의 다른 글

pascal 24765번 Mia (백준)  (0) 2025.09.01
pascal 15079번 Arggggggh! (백준)  (0) 2025.08.31
pascal 31097번 Astrology (백준)  (0) 2025.08.31
pascal 6919번 Fraction Action (백준)  (0) 2025.08.29
pascal 7366번 Counting Sheep (백준)  (0) 2025.07.18
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/01   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함