-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLv5_다트게임.cpp
56 lines (53 loc) · 1016 Bytes
/
Lv5_다트게임.cpp
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
#include <string>
#include <iostream>
#include <vector>
using namespace std;
int solution(string dartResult) {
int answer = 0;
int prev = 0;
int num = 0;
int index = 0;
vector<int> ans;
for (int i = 0; i < dartResult.size(); ++i) {
if (dartResult[i] == '*') {
ans[index - 2] = ans[index - 2] * 2;
ans[index - 1] = ans[index - 1] * 2;
prev = ans[index - 1];
}
else if (dartResult[i] == '#') {
ans[index - 1] = -ans[index - 1];
prev = ans[index - 1];
}
else {
num = dartResult[i] - '0';
++i;
if (dartResult[i] == '0') {
num = 10;
++i;
}
char score;
score = dartResult[i];
if (score == 'S') {
num = pow(num, 1);
ans.push_back(num);
prev = num;
++index;
}
else if (score == 'D') {
num = pow(num, 2);
ans.push_back(num);
prev = num;
++index;
}
else if (score == 'T') {
num = pow(num, 3);
ans.push_back(num);
prev = num;
++index;
}
}
}
for (auto a : ans)
answer += a;
return answer;
}