[백준] 6764

당당·2023년 7월 5일
0

백준

목록 보기
177/179

https://www.acmicpc.net/problem/6764

📔문제

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.


📝예제 입력 1

1
10
12
13

📺예제 출력 1

Fish Rising

🔍출처

Olympiad > Canadian Computing Competition & Olympiad > 2012 > CCC 2012 Junior Division 2번


🧮알고리즘 분류

  • 구현

📃소스 코드

import java.util.Scanner;

public class Code6764 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);

        int[] depth=new int[4];
        for(int i=0;i<4;i++){
            depth[i]=sc.nextInt();
        }
        if(depth[0]<depth[1] && depth[1]<depth[2] && depth[2]<depth[3]){
            System.out.println("Fish Rising");
        }
        else if(depth[0]>depth[1] && depth[1]>depth[2] && depth[2]>depth[3]){
            System.out.println("Fish Diving");
        }
        else if(depth[0]==depth[1] && depth[1]==depth[2] && depth[2]==depth[3]){
            System.out.println("Fish At Constant Depth");
        }
        else{
            System.out.println("No Fish");
        }
    }
}


📰출력 결과


📂고찰

Constant Depth라고만 출력했다가 한번 틀렸었다.

0<1<2<3 이면 Fish Rising
0>1>2>3 이면 Fish Diving
0=1=2=3 이면 Fish at Constant Depth
그 외는 No Fish

로 출력하면 된다.

profile
MySQL DBA 신입 지원

0개의 댓글