九度OJ_1355

开始的时候没有考虑到0 1 4 5 6这种情况,

#define _CRT_SECURE_NO_DEPRECATE

#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;

bool IfLianxu(int n, int a[])
{
    int count = 0;// 记录大王和小王的数
    for (int i = 0; i < n-1; i++)
    {
        if (a[i] == 0)
        {
            count++;
            if (count >4)
                return false;
            continue;
        }
        else
        {
            if (a[i + 1] == a[i])
                return false;
            if (a[i + 1] - a[i] == 1)
            {
                continue;
            }
            else
            {
                count = count - a[i+1]+a[i]+1;
                if (count <= -1)
                    return false;
            }
        }
    }
    return true;
}
int main()
{
    int n;
    int a[20];
    while (scanf("%d", &n))
    {
        if (n == 0)
            break;
        for (size_t i = 0; i < n; i++)
        {
            scanf("%d", &a[i]);
        }
        sort(a,a+n);
        if (IfLianxu(n,a))
            printf("So Lucky!\n");
        else
        {
            printf("Oh My God!\n");
        }
    }
    return 0;
}

终于Accepted了,做了好几题,不是这错就是拿错,

你可能感兴趣的:(C++-基础)