stack应用
#include <iostream> #include <cmath> #include <stack> #define max 3005 using namespace std; int t[max]; stack<int> a; void clear() { while (!a.empty()) a.pop(); } int main() { int n; while (cin >> n) { int sub, tmp, flag = 1; for (int i = 1; i <= n - 1; i++) a.push(i); cin >> sub; for (int i = 1; i < n; i++) { cin >> tmp; sub = (int)fabs(sub - tmp); t[i-1] = sub; sub = tmp; } while (!a.empty()) { int k = a.top(); for (int j = 0; j < n - 1; j++) if (a.top() == t[j]) a.pop(); if (!a.empty() && a.top() == k) { cout << "Not jolly\n"; flag = 0; break; } } if (flag) cout << "Jolly\n"; clear(); } return 0; }