题意看了老半天,就是说给一个序列[1, n],看是否是(1, 2, 3, ... n),入栈以后出栈时可以得到的序列。
My Code:
View Code
#include#include using namespace std; const int N = 100007; int st1[N], st2[N]; int main() { //freopen("data.in", "r", stdin); int i, top1, top2, n; while(cin >> n) { for(i = 0; i < n; i++) { cin >> st2[i]; } top1 = 0; top2 = 0; for(i = 1; i <= n; i++) { st1[++top1] = i; while(top1 != 0 && st1[top1] == st2[top2]) { --top1; ++top2; } } if(top1) cout << "Cheater"; else cout << "Not a proof"; cout << endl; } return 0; }