GitHub
CodingTest/백준/Silver/1541. 잃어버린 괄호 at main · kwon1232/CodingTest
This is an auto push repository for Baekjoon Online Judge created with [BaekjoonHub](https://github.com/BaekjoonHub/BaekjoonHub). - kwon1232/CodingTest
github.com
#include <vector>
#include <iostream>
#include <string>
#include <sstream>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <unordered_map>
#include <set>
#include <regex>
#include <tuple>
#include <cmath>
using namespace std;
vector<string> split(string input, char delimiter);
int mySum(string a);
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
std::cout.tie(NULL);
int answer = 0;
string example;
cin >> example;
vector<string> str = split(example, '-');
for (int i = 0; i < str.size(); i++)
{
int temp = mySum(str[i]);
if (i == 0)
{
answer = answer + temp;
}
else {
answer = answer - temp;
}
}
cout << answer << "\n";
return 0;
}
vector<string> split(string input, char delimiter)
{
vector<string> result;
stringstream ss(input);
string splitdata;
while (getline(ss, splitdata, delimiter))
{
result.push_back(splitdata);
}
return result;
}
int mySum(string a)
{
int sum = 0;
vector<string> temp = split(a, '+');
for (int i = 0; i < temp.size(); i++)
{
sum += stoi(temp[i]);
}
return sum;
}
https://www.acmicpc.net/problem/1541
'콘솔창 & 윈도우창 > 코딩 테스트' 카테고리의 다른 글
[백준 골드 5] 1456 거의 소수 (0) | 2025.04.26 |
---|---|
[백준 실버3] 1929 소수 구하기 (0) | 2025.04.25 |
프로그래머스 LV.2 방문 길이 (0) | 2025.04.17 |
백준 골드5 회의실 배정 1913 (0) | 2025.04.16 |
백준 골드4 수묶기 1744 (0) | 2025.04.13 |