-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPG_17682.java
More file actions
59 lines (52 loc) · 1.79 KB
/
PG_17682.java
File metadata and controls
59 lines (52 loc) · 1.79 KB
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
import java.util.ArrayList;
class PG_17681 {
public int solution(String dartResult) {
int answer = 0;
ArrayList<Integer> scores = new ArrayList<>(); //최종 점수 3개를 저장하는 배열
int i = 0;
//점수 저장 부분
while(i<dartResult.length()){
int num = 0;
if (Character.isDigit(dartResult.charAt(i)) && Character.isDigit(dartResult.charAt(i+1))){ //연속으로 숫자가 2자리일때(10일 경우)
num = 10;
i+=2;
}
else if (Character.isDigit(dartResult.charAt(i))){
num = dartResult.charAt(i) - '0';
i++;
}
//문자 저장 부분
if(dartResult.charAt(i) == 'S'){
scores.add(num);
}
else if(dartResult.charAt(i) == 'D'){
scores.add(num*num);
}
else{
scores.add(num*num*num);
}
//마지막에 옵션 없으므로 종료
i++;
if(i==dartResult.length()){
break;
}
//옵션 적용 부분
int index = scores.size()-1; //옵션을 적용할 점수가 몇번째인지
if(dartResult.charAt(i)=='*'){
scores.set(index, scores.get(index)*2);
if(index!=0){
scores.set(index-1, scores.get(index-1)*2);
}
i++;
}
else if(dartResult.charAt(i)=='#'){
scores.set(index, scores.get(index)*(-1));
i++;
}
}
for (int score : scores){
answer+=score;
}
return answer;
}
}