Skip to content

Commit

Permalink
잃어버린 괄호
Browse files Browse the repository at this point in the history
  • Loading branch information
yewon-yw authored Apr 30, 2022
1 parent e28403b commit 8aa8e95
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions greedy_algorithm/1541.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
#include <string>
using namespace std;

int main() {
string inp, num = "";
int result = 0, isMinus = 0;
cin >> inp;
for (int i = 0; i <= inp.size(); i++) {
if (inp[i] == '+' || inp[i] == '-' || i == inp.size()) {
if (isMinus) {
result -= stoi(num);
num = "";
}
else {
result += stoi(num);
num = "";
}
}
else num += inp[i];
if (inp[i] == '-') isMinus = 1;
}
cout << result << endl;
}

0 comments on commit 8aa8e95

Please sign in to comment.