import java.util.ArrayList;
public class DartsGame {
public int solution(String dartResult) {
int answer = 0;
ArrayList<String> list = new ArrayList<>();
ArrayList<Integer> scoreList = new ArrayList<>();
int index = 0;
char temp;
for (int i = 1; i <= dartResult.length(); i++) {
temp = dartResult.charAt(i - 1);
if (!(temp >= '0' && temp <= '9')) {
if (temp != '#' && temp != '*') {
list.add(dartResult.substring(index, i - 1));
}
list.add(temp + "");
index = i;
}
}
System.out.println(list + " - list");
for (int i = 1; i < list.size(); i++) {
if (list.get(i).equals("S")) {
scoreList.add((int) Math.pow(Integer.parseInt(list.get(i - 1)), 1));
} else if (list.get(i).equals("D")) {
scoreList.add((int) Math.pow(Integer.parseInt(list.get(i - 1)), 2));
} else if (list.get(i).equals("T")) {
scoreList.add((int) Math.pow(Integer.parseInt(list.get(i - 1)), 3));
} else if (list.get(i).equals("*")) {
scoreList.set(scoreList.size() - 1, scoreList.get(scoreList.size() - 1) * 2);
if (scoreList.size() >= 2) {
scoreList.set(scoreList.size() - 2, scoreList.get(scoreList.size() - 2) * 2);
}
} else if (list.get(i).equals("#")) {
scoreList.set(scoreList.size() - 1, scoreList.get(scoreList.size() - 1) * -1);
}
}
System.out.println(scoreList + " - scoreList");
for (int ele : scoreList) {
answer += ele;
}
return answer;
}
public static void main(String[] args) {
DartsGame s = new DartsGame();
System.out.println(s.solution("1S2D*3T"));
System.out.println(s.solution("1D2S#10S"));
System.out.println(s.solution("1D2S0T"));
System.out.println(s.solution("1S*2T*3S"));
System.out.println(s.solution("1D#2S*3S"));
System.out.println(s.solution("1T2D3D#"));
System.out.println(s.solution("1D2S3T*"));
}
}