1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| #include <string>
#include <vector>
#include <sstream>
using namespace std;
int solution(string my_string) {
int answer = 0;
stringstream ss(my_string);
string c;
string word;
while(getline(ss,word,' ')){
c+=word;
}
answer = stoi(c);
for(int i=1; i<c.size(); i++){
if(c[i]=='+'){
i++;
answer+=c[i] - 48;
}else if(c[i]=='-'){
i++;
answer-=c[i] - 48;
}
}
return answer;
}
|