-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1541.cpp
More file actions
47 lines (38 loc) · 787 Bytes
/
1541.cpp
File metadata and controls
47 lines (38 loc) · 787 Bytes
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
cin.tie(NULL);
ios::sync_with_stdio(false);
string N, temp = "";
int sum = 0;
bool Isminus = false;
cin >> N;
for (int i = 0; i < N.size(); i++)
{
if (N.at(i) == '+' || N.at(i) == '-' || N.at(i) == '\0')
{
// 기호가 마이너스라면
if (Isminus)
sum = sum - stoi(temp);
// 기호가 플러스라면
else
sum = sum + stoi(temp);
// 초기화
temp = "";
if (N.at(i) == '-')
Isminus = true;
continue;
}
temp = temp + N.at(i);
}
// 기호가 마이너스라면
if (Isminus)
sum = sum - stoi(temp);
// 기호가 플러스라면
else
sum = sum + stoi(temp);
cout << sum;
}