-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollercoaster3.cpp
More file actions
50 lines (38 loc) · 982 Bytes
/
rollercoaster3.cpp
File metadata and controls
50 lines (38 loc) · 982 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
// NOTE: it is recommended to use this even if you don't understand the following code.
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
// uncomment the two following lines if you want to read/write from files
// ifstream cin("input.txt");
// ofstream cout("output.txt");
int N;
cin >> N;
string S;
cin >> S;
int K = 0;
// INSERT YOUR CODE HERE
int sum = 0;
int H_count = 0;
for (int i=0; i<N; i++) {
if (S[i] == 'D') sum += 9;
else if (S[i] == 'B') sum += 10;
else if (S[i] == 'U') sum -= 11;
else if (S[i] == 'H') H_count ++;
if (sum <= 0) {
while (H_count && sum <= 0) {
sum += 10;
K ++;
H_count --;
}
if (sum <= 0) {
K = -1;
break;
}
}
}
cout << K << endl;
return 0;
}