문자열? 파이썬으로 풀어야지. 라고 생각했는데 줄 수 주어지지 않은 입력을 어떻게 받아야 할지 몰라서 그냥 c++로 짰다.
먼저 문자열 다 입력받은 다음에 하나의 문자열로 만들어주고
숫자면 임시 문자열에 붙이고 콤마를 만났을 때 임시 문자열을 숫자로 만들어주었다
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = long long;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
int main()
{
string in, str = "";
while (cin >> in)
str += in;
string tmp = "";
int sum = 0;
for (int i = 0; i < str.size(); i++)
{
if (str[i] == ',')
{
sum += stoi(tmp);
tmp = "";
continue;
}
tmp += str[i];
}
sum += stoi(tmp);
cout << sum;
return 0;
}
'백준' 카테고리의 다른 글
1094 막대기 (0) | 2020.09.16 |
---|---|
6246 풍선 놀이 (0) | 2020.09.16 |
2194 유닛 이동시키기 (0) | 2020.09.11 |
16943 숫자 재배치 (0) | 2020.09.11 |
14465 소가 길을 건너간 이유 5 (0) | 2020.09.09 |