summaryrefslogtreecommitdiff
path: root/514/rails.cpp
diff options
context:
space:
mode:
Diffstat (limited to '514/rails.cpp')
-rw-r--r--514/rails.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/514/rails.cpp b/514/rails.cpp
new file mode 100644
index 0000000..d2f373b
--- /dev/null
+++ b/514/rails.cpp
@@ -0,0 +1,46 @@
+#include <iostream>
+#include <stack>
+using namespace std;
+
+bool in(stack<int> s, int num){
+ bool found=false;
+ while(!found && s.size()>0){
+ found=(s.top()==num);
+ s.pop();
+ }
+ return found;
+}
+
+int main(){
+ int num;
+ cin>>num;
+ while(num!=0){
+ stack<int> s, orig;
+ for(int i=num; i>0; i--)
+ orig.push(i);
+
+ bool possible=true, end=false;
+
+ while(!end){
+ int x;
+ cin>>x;
+ if(x==0){
+ cout<<endl;
+ end=true;
+ }
+ else{
+ for(int i=0; i<num-1 && possible; i++){
+ while(!in(s, x)){
+ s.push(orig.top());
+ orig.pop();
+ }
+ if(x!=s.top())
+ possible=false;
+ cin>>x;
+ }
+ possible? cout<<"Yes\n" : cout<<"No\n";
+ }
+ }
+ cin>>num;
+ }
+}