SDNU 1108.Happy luguans(水题)

Description

A sequence of n > 0 integers is called a happy luguan if the absolute values of the difference between successive elements take on all the values 1 through n-1. For instance,

1 4 2 3

is a happy luguan, because the absolutes differences are 3, 2, and 1 respectively. The definition implies that any sequence of a single integer is a happy luguan. You are to write a program to determine whether or not each of a number of sequences is a happy luguan.

Input

Each line of input contains an integer n <= 3000 followed by n integers representing the sequence.

Output

For each line of input, generate a line of output saying "Happy luguan" or "Not happy luguan".

Sample Input

4 1 4 2 3
5 1 4 2 -1 6

Sample Output

Happy luguan
Not happy luguan

Source

SDNU ACM-ICPC 2012 Training Weekly Contest(Freshman/12-16)
#include<bits/stdc++.h>
using namespace std;

int n, a[10000+8];

int main()
{
    while(~scanf("%d", &n) && n != 0)
    {
        bool flag = 1;
        for(int i = 0; i<n; i++)
            scanf("%d", &a[i]);
        for(int i = 0; i<n-1; i++)
        {
            int number = abs(a[i]-a[i+1]);
            if(number>0 && number<n)continue;
            else
            {
                flag = 0;
                break;
            }
        }
        if(flag)printf("Happy luguan\n");
        else printf("Not happy luguan\n");
    }
    return 0;
}

 

上一篇:PTA编程总结3


下一篇:PTA编程总结3