Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1541번 - 파싱 이용 #6

Open
illuminoplanet opened this issue Sep 7, 2020 · 0 comments
Open

1541번 - 파싱 이용 #6

illuminoplanet opened this issue Sep 7, 2020 · 0 comments

Comments

@illuminoplanet
Copy link
Contributor

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

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

    string s; cin >> s;
    int n = s.size();

    vector<int> number;
    int minus = 0;
    for (int i = 0; i < n; i++)
    {
        if (isdigit(s[i]))
        {
            int j = i;
            while (j+1 < n && isdigit(s[j+1])) j++;
            int parsed = stoi(s.substr(i, j-i+1));
            number.push_back(parsed);
            i = j;
        }
        if (!minus && s[i] == '-') minus = number.size();
    }

    if (!minus) minus = number.size();

    int result = accumulate(number.begin(), number.begin()+minus, 0)-accumulate(number.begin()+minus, number.end(), 0);
    cout << result << endl;
    return 0;
}
@illuminoplanet illuminoplanet changed the title 1541번 다른 코드 1541번 - 파싱 해결법 Sep 7, 2020
@illuminoplanet illuminoplanet changed the title 1541번 - 파싱 해결법 1541번 - 파싱 이용 Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant