ACM UVA 10038 (Problem E: Jolly Jumpers)

727阅读 0评论2009-06-28 chnos
分类:

题目:

思路: 简单题

代码:

/*
 * UVA 10038
 * Ye Xiaofeng
 */

#include <iostream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ON 1

int main()
{
    int n = 0;
    int array[3000];
    int v1 = 0;
    int v2 = 0;
    int i = 0;
    int flg = 1;
    int tmp = 0;

    while (cin >> n) {
        memset(array, 0, 3000*sizeof(int));
        if (1 == n) {
            cin >> v1;
            cout << "Jolly" << endl;
            continue;
        }
        flg = 1;
        cin >> v1;
        for (i = 0; i < n-1; i++) {
            cin >> v2;
            tmp = abs(v1-v2);
            if (tmp < 3000 && tmp >= 1) {
                array[tmp] = ON;
            }
            v1 = v2;
        }
        for (i = 1; i <= n-1; i++) {
            if (array[i] != ON) {
                flg = 0;
                break;
            }
        }
        if (flg) {
            cout << "Jolly" << endl;
        } else {
            cout << "Not jolly" << endl;
        }
    }
}

上一篇:ACM UVA 10037 (Problem D: Bridge)
下一篇:博客已升级,请注意变更地址