작성일 :

문제 링크

6764번 - Sounds fishy!

설명

연속 네 번의 깊이 측정값이 주어질 때, 물고기의 이동 상태를 출력하는 문제입니다.


접근법

네 값이 엄격히 증가하면 Fish Rising, 엄격히 감소하면 Fish Diving을 출력합니다.

모두 같으면 Fish At Constant Depth, 그 외에는 No Fish를 출력합니다.

인접한 값들을 비교하여 증가, 감소, 동일 여부를 판별합니다.



Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System;

class Program {
  static void Main() {
    var d = new int[4];
    for (var i = 0; i < 4; i++)
      d[i] = int.Parse(Console.ReadLine()!);

    bool inc = true, dec = true, same = true;
    for (var i = 1; i < 4; i++) {
      if (d[i] <= d[i - 1]) inc = false;
      if (d[i] >= d[i - 1]) dec = false;
      if (d[i] != d[i - 1]) same = false;
    }

    if (inc) Console.WriteLine("Fish Rising");
    else if (dec) Console.WriteLine("Fish Diving");
    else if (same) Console.WriteLine("Fish At Constant Depth");
    else Console.WriteLine("No Fish");
  }
}

C++

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
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int d[4];
  for (int i = 0; i < 4; i++)
    cin >> d[i];

  bool inc = true, dec = true, same = true;
  for (int i = 1; i < 4; i++) {
    if (d[i] <= d[i-1]) inc = false;
    if (d[i] >= d[i-1]) dec = false;
    if (d[i] != d[i-1]) same = false;
  }

  if (inc) cout << "Fish Rising\n";
  else if (dec) cout << "Fish Diving\n";
  else if (same) cout << "Fish At Constant Depth\n";
  else cout << "No Fish\n";

  return 0;
}