Skip to content

Commit

Permalink
Add zco14001.cpp (gopalgoel19#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
pulkit03 authored and gopalgoel19 committed Oct 7, 2017
1 parent 08bb177 commit 239b9e8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions codechef/zco14001.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include<iostream>

using namespace std;

int main()
{
int n,h;
cin>>n>>h;
int stack[n];
for(int i=0;i<n;++i)
cin>>stack[i];
int com,crane=0,loaded=0;
do
{
cin>>com;
switch(com)
{
case 1: if(crane != 0) crane--;break;
case 2: if(crane != (n-1)) crane++;break;
case 3: if(loaded == 0 && stack[crane] != 0){stack[crane]--; loaded = 1;}break;
case 4: if(loaded == 1 && stack[crane] != (h)){stack[crane]++; loaded = 0;}break;
}
}while(com!=0);
for(int i=0; i<n;++i)
{
cout<<stack[i]<<" ";
}
}

0 comments on commit 239b9e8

Please sign in to comment.