GitHub - jzplp/aoapc-UVA-Answer: 算法竞赛入门经典 例题和习题答案 刘汝佳 第二版https://github.com/jzplp/aoapc-UVA-Answer
AC代码
#include#include #include using namespace std; int N; int handle() { int i, j, k, t; bool flag; stack st; j = 1; for(i = 0; i < N; ++i) { cin >> t; flag = false; if(t == 0) { return 0; } if(st.size() != 0 && st.top() == t) { st.pop(); continue; } while(j <= N) { if(j == t) { ++j; flag = true; break; } st.push(j); ++j; } if(flag == true) { continue; } cout <<"No" << endl; return 1; } cout << "Yes" << endl; return 1; } int main() { string s; while(cin >> N && N > 0) { while(handle()) { getline(cin, s); } cout << endl; } return 0; }



