forked from vaibhavpathak999/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoGame.cpp
More file actions
69 lines (66 loc) · 833 Bytes
/
Copy pathVideoGame.cpp
File metadata and controls
69 lines (66 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
/*string removeSpaces(string str)
{
str.erase(remove(str.begin(), str.end(), ' '), str.end());
return str;
}*/
int main()
{
long long int n,h,j=0,k=0;
int a[100000],b[100000];
string str;
cin>>n>>h;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cin.ignore();
getline(cin, str);
//str = removeSpaces(str);
int x=str.length();
for(int i=0;i<str.length();i++)
{
if(str[i]=='1')
{
if(j>=1)
j--;
}
else
if(str[i]=='2')
{
if(j<n-1)
j++;
}
else
if(str[i]=='3')
{
if(k==0&&a[j]>0)
{
a[j]--;
k=1;
}
}
else
if(str[i]=='4')
{
if(k==1&&a[j]<h)
{
a[j]++;
k=0;
}
}
else
if(str[i]=='0')
{
break;
}
}
for(int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
return 0;
}