From 36e8897c90442cd558cdddf3f2ae38f148ac5581 Mon Sep 17 00:00:00 2001 From: Aditya Naik Date: Mon, 8 Jun 2020 21:17:18 -0400 Subject: Older files and necklace --- 514/in | 3 +++ 514/rails | Bin 0 -> 105376 bytes 514/rails.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 514/test | Bin 0 -> 105176 bytes 514/test.cpp | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+) create mode 100644 514/in create mode 100755 514/rails create mode 100644 514/rails.cpp create mode 100755 514/test create mode 100644 514/test.cpp (limited to '514') diff --git a/514/in b/514/in new file mode 100644 index 0000000..5389a20 --- /dev/null +++ b/514/in @@ -0,0 +1,3 @@ +5 +5 4 1 2 3 +0 diff --git a/514/rails b/514/rails new file mode 100755 index 0000000..e5289b5 Binary files /dev/null and b/514/rails differ 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 +#include +using namespace std; + +bool in(stack 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 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<>x; + } + possible? cout<<"Yes\n" : cout<<"No\n"; + } + } + cin>>num; + } +} diff --git a/514/test b/514/test new file mode 100755 index 0000000..2483dfc Binary files /dev/null and b/514/test differ diff --git a/514/test.cpp b/514/test.cpp new file mode 100644 index 0000000..2f79f72 --- /dev/null +++ b/514/test.cpp @@ -0,0 +1,37 @@ +#include +#include +using namespace std; + +bool in(stack 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 s, orig; + for(int i=num; i>0; i--) + orig.push(i); + + bool possible=true, end=false; + int x; + for(int i=0; i>x; + while(!in(s, x)){ + s.push(orig.top()); + orig.pop(); + } + if(x!=s.top()) + possible=false; + + } + possible? cout<<"Yes\n" : cout<<"No\n"; + cin>>num; + } +} -- cgit v1.2.3