summaryrefslogtreecommitdiff
path: root/514/rails.cpp
diff options
context:
space:
mode:
authorAditya Naik2020-06-08 21:17:18 -0400
committerAditya Naik2020-06-08 21:17:18 -0400
commit36e8897c90442cd558cdddf3f2ae38f148ac5581 (patch)
tree9f62cfe733ffced1fa7a0916750ac24af5ac5112 /514/rails.cpp
parent7f1d8a56cd3d5065e442b8e592ffe17d40d4c3d2 (diff)
Older files and necklace
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;
+ }
+}