둥지/알고리즘
[프로그래머스] 컨트롤 제트
까닭
2023. 2. 26. 15:25
#include <string>
#include <stack>
#include <sstream>
using namespace std;
int solution(string s)
{
int answer = 0;
stringstream ss("");
ss.str(s);
stack<int> numbers = {};
while (false == ss.eof())
{
string str = {};
ss >> str;
if ("Z" == str)
{
answer -= numbers.top();
continue;
}
int num = stoi(str);
numbers.push(num);
answer += num;
}
return answer;
}