zoukankan      html  css  js  c++  java
  • 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

    #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
    ");
            else printf("Not happy luguan
    ");
        }
        return 0;
    }
  • 相关阅读:
    ASP.NET 5
    asp.net web api
    PowerShell 常用命令
    WinDbg
    Visual Studio Online
    asp.net authentication
    CoreOS
    解决download.msdn.microsoft.com无法正确解析而无法下载的问题
    nodejs express
    移动平台WEB前端开发技巧汇总
  • 原文地址:https://www.cnblogs.com/RootVount/p/10969909.html
Copyright © 2011-2022 走看看