Post

[SWEA] 12741. ๋‘ ์ „๊ตฌ(python)

๐Ÿ“Œ๋ฌธ์ œ

Alt text

๐Ÿ’ช์•„์ด๋””์–ด

์ „๊ตฌ๊ฐ€ ๋งˆ์ง€๋ง‰์— ์ผœ์ง€๋Š” ์‹œ๊ฐ„์˜ ์ตœ์†Ÿ๊ฐ’ - ์ „๊ตฌ๊ฐ€ ์ฒ˜์Œ์— ์ผœ์ง€๋Š” ์‹œ๊ฐ„์˜ ์ตœ๋Œ“๊ฐ’์„ ๋นผ๋ฉด ๊ฒน์น˜๋Š” ์ดˆ๊ฐ€ ๋ฐ˜ํ™˜๋œ๋‹ค. ์Œ์ˆ˜๋ฉด ๊ฒน์น˜์ง€ ์•Š๋Š”๋‹ค๊ณ  ํŒ๋‹จํ•˜๊ณ  0์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

๐Ÿฅ‚์ฝ”๋“œ

1
2
3
4
5
6
7
8
9
answers=[]
for _ in range(int(input())):
    a,b,c,d = map(int,input().split())
    light = min(b,d)-max(a,c)
    if light>0: answers.append(light)
    else: answers.append(0)

for i,answer in enumerate(answers):
    print('#{} {}'.format(i+1,answer))
This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.