뜌릅

Auxiliary Question of the Universe 3550번 [백준] 본문

카테고리 없음

Auxiliary Question of the Universe 3550번 [백준]

TwoCastle9 2022. 11. 14. 21:13
반응형

 

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

 

3550번: Auxiliary Question of the Universe

As you probably know, scientists already discovered the Ultimate question of life, the Universe, and everything, and it is "What do you get if you multiply six by nine?". Not satisfied by this, the scientists contracted a small Magrateyan company to constr

www.acmicpc.net

 

해당 symbol들을 가지고 문법에 맞게 표현만 하면 되는 문제이다.

 

#include<bits/stdc++.h>


using namespace std;
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;

void solve() {
    string s;
    cin >> s;

    queue<char> q;

    bool first = true;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '(' || s[i] == ')') {
            if (!(first || q.back() == '+')) {
                q.push('+');
            }
            q.push('(');
            q.push('0');
            q.push(')');
        }else if (s[i] == '+') {
            if (first || q.back() == '+')q.push('0');
            q.push('+');
        } else {//num
            if (first || q.back() == '+')q.push(s[i]);
            else {
                q.push('+');
                q.push(s[i]);
            }
        }
        first = false;
    }

    if (q.back() == '+') {
        q.push('0');
    }

    while (!q.empty()) {
        cout << q.front();
        q.pop();
    }
}

int main() {

    fast_io;
    solve();
    return 0;
}
반응형