프로그래머스 181865 간단한 식 계산하기

Jmnote (토론 | 기여)님의 2023년 11월 16일 (목) 22:01 판
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

프로그래머스 181865 간단한 식 계산하기

2 C++[ | ]

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

using namespace std;

int solution(string binomial) {
    int a, b;
    char op;
    stringstream ss(binomial);
    ss >> a >> op >> b;
    switch(op) {
        case '+': return a+b;
        case '-': return a-b;
        case '*': return a*b;
    }
    return -9999;
}