문제 링크 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14mbSaAEwCFAYD


문제의 저작권은 SW Expert Academy에 있습니다.



#include <iostream>
#include <stack>
 
using namespace std;
 
int main(void) {
    int length;
    char temp;
    string input;
 
 
    for(int t_case=0; t_case<10; t_case++) {
        string postfix = "";
 
        cin >> length;
        cin >> input;
 
        for(int i=0; i<length; i++) {
            if(input.at(i) == '+') {
                postfix += input.at(++i);
                postfix += '+';
            } else {
                postfix += input.at(i);
            }
        }
 
        int answer = 0;
        for(int i=0; i<length; i++) {
            if(postfix.at(i) != '+')
                answer += (postfix.at(i) - '0');
        }
 
        cout << "#" << t_case+1 << " " << answer << "\n";
    }
 
    return 0;
}
cs

+ Recent posts