Scroll indicator done
728x90

https://www.acmicpc.net/problem/1541


#include <iostream>
#include <string>
using namespace std;

int n = 0;
int m = 0;
string nums = "";
string s;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> s;
	for (int i = 0; i <= s.size(); ++i) {
		if (s[i] == '+' || s[i] == '-' || s[i] == '\0') {
			if (m) n -= stoi(nums);
			else n += stoi(nums);

			if (s[i] == '-') m = 1;
			nums = "";
			continue;
		}
		nums += s[i];
	}
	cout << n << '\n';	
	return 0;
}
728x90

'BAEKJOON > C++' 카테고리의 다른 글

[B9375][패션왕 신해빈][C++]  (0) 2021.06.29
[B11727][2xn 타일링 2][C++]  (0) 2021.06.29
[B11659][구간 합 구하기 4][C++]  (0) 2021.06.24
[B1676][팩토리얼 0의 개수][C++]  (0) 2021.06.23
[B1260][DFS와 BFS][C++]  (0) 2021.06.23