문제
A fish-finder is a device used by anglers to find fish in a lake. If the fish-finder finds a fish, it will sound an alarm. It uses depth readings to determine whether to sound an alarm. For our purposes, the fish-finder will decide that a fish is swimming past if:
- there are four consecutive depth readings which form a strictly increasing sequence (such as 3 4 7 9) (which we will call “Fish Rising”), or
- there are four consecutive depth readings which form a strictly decreasing sequence (such as 9 6 5 2) (which we will call “Fish Diving”), or
- there are four consecutive depth readings which are identical (which we will call “Constant Depth”).
All other readings will be considered random noise or debris, which we will call “No Fish.”
Your task is to read a sequence of depth readings and determine if the alarm will sound.
입력
The input will be four positive integers, representing the depth readings. Each integer will be on its own line of input.
출력
The output is one of four possibilities. If the depth readings are increasing, then the output should be Fish Rising. If the depth readings are decreasing, then the output should be Fish Diving. If the depth readings are identical, then the output should be Fish At Constant Depth. Otherwise, the output should be No Fish.
풀이
fish = [int(input()) for _ in range(4)]
ans = 0
for i in range(3):
if fish[i+1] > fish[i]:
ans += 1
elif fish[i+1] < fish[i]:
ans -= 1
if len(set(fish)) == 1:
print('Fish At Constant Depth')
elif ans == 3:
print('Fish Rising')
elif ans == -3:
print('Fish Diving')
else:
print('No Fish')
'Develop > 알고리즘' 카테고리의 다른 글
[백준/Python] Bronze I #10448 유레카 이론 (0) | 2023.08.25 |
---|---|
[백준/Python] Silver IV #11652 카드 (0) | 2023.08.25 |
[백준/Python] Silver III #1735 분수 합 (0) | 2023.08.25 |
[백준/Python] Silver I #11729 하노이 탑 이동 순서 (0) | 2023.08.25 |
[백준/Python] Silver I #1105 팔 (0) | 2023.08.23 |
Comment