Algorithm 🧑🏻‍💻/백준(BOJ)

[백준,c++] 10822번 - 더하기

dkswnkk 2021. 10. 24. 22:14
 

10822번: 더하기

첫째 줄에 문자열 S가 주어진다. S의 길이는 최대 100이다. 포함되어있는 정수는 1,000,000보다 작거나 같은 자연수이다.

www.acmicpc.net

#include <iostream>
#include <vector>
#include <sstream>
#include <string>


using namespace std;
vector<string>v;

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

    vector<string>v;
    string s; cin >> s;
    string stringBuffer;
    stringstream ss(s);

    while (getline(ss, stringBuffer, ',')) {
        v.push_back(stringBuffer);
    }

    int ans = 0;
    for (int i = 0; i < v.size(); i++) {
        ans += stoi(v[i]);
    }
    cout << ans;




}