시키는대로 하면 되는 문제였다.
다만 10처리 해줄때만 조심하면 되었다.
#include <string>
using namespace std;
int solution(string dartResult) {
int answer = 0;
int prev = 0;
for (int i = 0; i < dartResult.size(); i += 2)
{
int score = dartResult[i] - '0';
if (dartResult[i + 1] == '0')
{
score = 10;
i++;
}
if (dartResult[i + 1] == 'D')
score *= score;
if (dartResult[i + 1] == 'T')
score *= score * score;
if (dartResult[i + 2] == '#')
{
score *= -1;
i++;
}
else if (dartResult[i + 2] == '*')
{
score *= 2;
answer += prev;
i++;
}
answer += score;
prev = score;
}
return answer;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV1 두 정수 사이의 합 (0) | 2022.04.25 |
|---|---|
| [프로그래머스] (C++) LV1 같은 숫자는 싫어 (0) | 2022.04.25 |
| [프로그래머스] (C++) LV1 가운데 글자 가져오기 (0) | 2022.04.25 |
| [프로그래머스] (C++) LV1 비밀지도 (0) | 2022.04.25 |
| [프로그래머스] (C++) LV1 부족한 금액 계산하기 (0) | 2022.04.25 |