day029-2019-08-30

本文详细介绍了一种用于垂钓的鱼群探测器的工作原理,该设备通过深度读数判断是否有鱼正在上升、下降或保持恒定深度。文章提供了算法的具体实现,包括如何通过连续四个深度读数来确定鱼的行为模式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有鱼的声音

题目描述 Description

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:

fish-finder是一个神奇的装置供垂钓者使用区在护理钓鱼。如果一个f-f找到了一条鱼,他会响起声音警报。它用鱼的深度来决定是否响警报。我们的目的就是要决定鱼是否通过,具体如下:


• 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

如果连续的四个深度读入是严格递增的序列,我们可以叫它 Fish Rising 。


• 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

如果连续的四个深度读入是严格递减的序列,我们可以叫它 Fish Diving 。


• 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.

如果连续的四个深度读入是一样的,那就是“Fish At Constant Depth”。如果都不是,就是“No Fish”。

输入描述 Input Description

The input will be four positive integers, representing the depth readings. Each integer will be on its own line of input.

输入会是四个正整数,代表深度读入。每个整数会占一行。

输出描述 Output Description

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.

输出就是四种情况。

样例输入 Sample Input

样例1:

30 10 20 20

样例2:

1 10 12 13

样例输出 Sample Output

样例1:

No Fish

样例2:

Fish Rising

数据范围及提示 Data Size & Hint

数据很小

C++编程实现 

#include<iostream>

using namespace std;

int main()
{
    int a[4];
    int b=0,c=0,d=0;
    for(int i=0;i<4;i++)
        cin>>a[i];
    for(int j=0;j<3;j++)
    {
        if(a[j]<a[j+1])b++;
        else if(a[j]>a[j+1]) c++;
        else if(a[j]==a[j+1]) d++;
    }
    if(b==3) cout<<"Fish Rising"<<endl;
    else
        if(c==3) cout<<"Fish Diving"<<endl;
    else
        if(d==3) cout<<"Fish At Constant Depth"<<endl;
    else
        cout<<"No Fish"<<endl;
    return 0;

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值