diff options
| author | Aditya Naik | 2020-06-08 21:17:18 -0400 |
|---|---|---|
| committer | Aditya Naik | 2020-06-08 21:17:18 -0400 |
| commit | 36e8897c90442cd558cdddf3f2ae38f148ac5581 (patch) | |
| tree | 9f62cfe733ffced1fa7a0916750ac24af5ac5112 /514 | |
| parent | 7f1d8a56cd3d5065e442b8e592ffe17d40d4c3d2 (diff) | |
Older files and necklace
Diffstat (limited to '514')
| -rw-r--r-- | 514/in | 3 | ||||
| -rwxr-xr-x | 514/rails | bin | 0 -> 105376 bytes | |||
| -rw-r--r-- | 514/rails.cpp | 46 | ||||
| -rwxr-xr-x | 514/test | bin | 0 -> 105176 bytes | |||
| -rw-r--r-- | 514/test.cpp | 37 |
5 files changed, 86 insertions, 0 deletions
@@ -0,0 +1,3 @@ +5 +5 4 1 2 3 +0 diff --git a/514/rails b/514/rails Binary files differnew file mode 100755 index 0000000..e5289b5 --- /dev/null +++ b/514/rails 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; + } +} diff --git a/514/test b/514/test Binary files differnew file mode 100755 index 0000000..2483dfc --- /dev/null +++ b/514/test 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 <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; + int x; + for(int i=0; i<num && possible; i++){ + cin>>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; + } +} |
