Wikioi 1275, the sound of a fish.

Source: Internet
Author: User
Topic Description Description

Afish-finder is a device used by anglers Tofindfish in a. If Thefish-finderfinds Afish, it would sound an alarm. It uses depth readings to determine whether to sound a alarm. For our purposes, Thefish-finder'll decide that Afish is swimming past if:

Fish-finder is a magical device for anglers who use the area in nursing fishing. If a f-f finds a fish, he will sound an alarm. It uses the depth of the fish to decide whether to ring the alarm. Our aim is to determine whether the fish is passed, as follows:


There are four consecutive depth readings which form a strictly increasing sequence (such as 3 4 7 9) (which we'll cal L "Fish Rising"), or

If a continuous four depth reading is a strictly incremental sequence, we can call it Fish rising.


There are four consecutive depth readings which form a strictly decreasing sequence (such as 9 6 5 2) (which we'll cal L "Fish Diving"), or

If a continuous four depth reading is a strictly descending sequence, we can call it Fish Diving.


There are four consecutive depth readings which are identical (which we'll call "Constant depth").
All the other readings'll be considered random noise or debris, which we'll call "No Fish."
Your task is to read a sequence of depth readings and determine if the alarm.

If four consecutive reads are the same, it is "Fish at Constant Depth". If not, it's "No Fish". Input description Input Description

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

The input will be four positive integers, representing the depth read. Each integer will occupy one row. Output Description 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 is Fish at Constant depth. Otherwise, the output should be No Fish.

Output is four kinds of cases. Sample Input For example

Sample 1:

30 10 20 20

Sample 2:

1 10 12 13 Sample output sample

Sample 1:

No Fish

Sample 2:

Fish rising data range and tips & Hint

The data is small.

#include <cstdio>
#include <cstdlib>

int deep[4];

int fish_rising (int a[])
{
    if (a[0]<a[1]&&a[1]<a[2]&&a[2]<a[3]) return
        1;
    return 0;
}

int fish_diving (int a[])
{
    if (a[1]>a[2]&&a[2]>a[3]&&a[0]>a[1]) return
        1;
    return 0;
}

int first_at_constant_depth (int a[])
{
    if (a[0]==a[1]&&a[0]==a[2]&&a[0]==a[3])
        return 1;
    return 0;
}
int main ()
{
    for (int i=0;i<4;i++)
        scanf ("%d", &deep[i]);
    int j1,j2,j3;
    J1=fish_rising (deep);
    J2=fish_diving (deep);
    J3=first_at_constant_depth (deep);
    if (J1)
        printf ("Fish Rising");
    else if (J2)
        printf ("Fish Diving");
    else if (J3)
        printf ("Fish at Constant Depth");
    else
        printf ("No Fish");
    return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.