https://www.acmicpc.net/problem/1541
#include <iostream>
#include <vector>
using namespace std;
// 잃어버린 괄호
int solution(string s){
int idx = 0;
int sum = 0;
vector<int> minus;
for(int i=0;i<s.size();i++){
if(s[i] == '-'){
int a = stoi(s.substr(idx, i- idx));
sum += a;
idx = i+1;
minus.push_back(sum);
sum = 0;
}else if(s[i] == '+' || i == s.size()-1){
int a;
if(i == s.size()-1)
a = stoi(s.substr(idx, i-idx+1));
else
a = stoi(s.substr(idx, i- idx));
sum += a;
idx = i+1;
}
}
minus.push_back(sum);
int answer = minus[0];
for(int i=1;i<minus.size();i++){
answer -= minus[i];
}
return answer;
}
#include <stdio.h>
int main()
{
char cmd;
int n,s,m=0;
for(scanf("%d",&s);scanf("%c",&cmd),cmd!=10;)
{
if(cmd=='-')m=1;
scanf("%d",&n);
if(m)s-=n;
else s+=n;
}
printf("%d",s);
return 0;
}