Cattle-off practice match 14 D compare the size of the moon (to achieve)

Links: https://ac.nowcoder.com/acm/contest/82/D
Source: Cattle-off network

Title Description

     He is an excellent little werewolf. As we all know, the only werewolf full moon night will turn into a wolf.

    Meanwhile, the size of the moon varies over time, its size changes in a cycle of 30 days. It changes (from the day one) is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then once again cycle.

    This summer is very little bored and began to look at the moon. Because little busy, so he only select a continuous period of time to see the moon, and the size of the moon recorded.

    Now, he tells you what he recorded, let him tell you the moon the next day (ie the day after the last day of the next little bit recording) is the day before (that is little record of the last day of) large or small.

Enter a description:

To give you a positive integer n represents the number of records in little time. 
The next line n natural numbers indicate the size of the moon little record of.

Output Description:

A string. 
If the next day the previous day's large output "UP"
, if the next day the previous day a small output "DOWN"
If the determination is not "-1"
Example 1

Entry

copy
5
3 4 5 6 7

Export

copy
UP
Example 2

Entry

copy
8
12 13 14 15 14 13 12 11

Export

copy
DOWN
Example 3

Entry

copy
1
8

Export

copy
-1

Remarks:

n≤100 0 ≤ a i ≤ 15
Cyclical nature of the input data to ensure that meet the changing moon
 
 
Ideas:
Special judge about 0 and 15, according to a number of other figures on to the sentence, if not a number on it or -1.
 
See details Code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
int a[maxn];
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    int n;    
    gbtb;
    cin>>n;
    repd(i,1,n)
    {
        cin>>a[i];
    }
    if(n==1)
    {
        if(a[1]==0)
        {
            cout<<"UP"<<endl;
        }else if(a[1]==15)
        {
            cout<<"DOWN"<<endl;
        }else
        {
            cout<<-1<<endl;
        }
    }else 
    {
        if(a[n]==0)
        {
            cout<<"UP"<<endl;
        }else if(a[n]==15)
        {
            cout<<"DOWN"<<endl;
        }else
        {
            if(a[n]>a[n-1])
            {
                cout<<"UP"<<endl;
            }else
            {
                cout<<"DOWN"<<endl;
            }
        }
    }
    
    
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}

 

 

Guess you like

Origin www.cnblogs.com/qieqiemin/p/10956361.html