#include <iostream> #include <cstring> #include <string> #include <stack> #define DEBUG if(false) using namespace std; int order[1000]; int n = 0; int moreToDo = 1; void simulate() { int targetCar = 1; int currentCar = 1; stack<int> station; while(currentCar <= n) { station.push(currentCar); DEBUG cout << "\nadding " << currentCar << " to station."; while(!station.empty() && (station.top() == order[targetCar])) { DEBUG cout << "\npopping car " << order[targetCar]; station.pop(); targetCar++; if(targetCar > n) break; } currentCar++; } if(station.empty()) cout << "Yes" << endl; else cout << "No" << endl; } void getTestCase() { while (1) { cin >> order[1]; if (order[1] == 0) return; for (int i = 2; i <= n; i++) cin >> order[i]; simulate(); } } int main() { while(moreToDo) { cin >> n; if(n > 0) getTestCase(); else moreToDo = 0; } return 0; }The statements and opinions included in these pages are those of only. Any statements and opinions included in these pages are not those of Louisiana State University or the LSU Board of Supervisors.
© 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015