#include <string>
#include <iostream>
#include <vector>
using namespace std;
 
int solution(string dartResult) 
{
    int answer = 0;
    vector<int> reserve;
    
    for(int i = 0; i < dartResult.size();)
    {
        string score;
        int j;
        for(j = i; dartResult[j] != 'S' && dartResult[j] != 'D' && dartResult[j] != 'T'; j++)
        {
            score += dartResult[j];
        }
        
        int scoreNum = stoi(score);
        if(dartResult[j] == 'S')
        {
            reserve.push_back(scoreNum);
        }
        else if(dartResult[j] == 'D')
        {
            reserve.push_back(scoreNum * scoreNum);
        }
        else if(dartResult[j] == 'T')
        {
            reserve.push_back(scoreNum * scoreNum * scoreNum);
        }
        
        j++;
        
        if(dartResult[j] == '*')
        {
            reserve[reserve.size()-1*= 2;
            if(reserve.size() >= 2)
            {
                reserve[reserve.size()-2*= 2;    
            }
            j++;
        }
        else if(dartResult[j] == '#')
        {
            reserve[reserve.size()-1*= -1;
            j++;
        }
        
        i = j;        
    }
    
    for(int i = 0; i < reserve.size(); i++)
    {
        answer += reserve[i];
    }
    
    return answer;
}
cs

+ Recent posts