SDNU 1108.Happy luguans(水题)
Posted rootvount
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.
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\n"); else printf("Not happy luguan\n"); return 0;
以上是关于SDNU 1108.Happy luguans(水题)的主要内容,如果未能解决你的问题,请参考以下文章