코딩테스트/프로그래머스 - LV 0
[프로그래머스] OX 퀴즈
웅드
2024. 1. 12. 22:24
#include <string>
#include <vector>
#include <sstream>
using namespace std;
vector<string> solution(vector<string> quiz) {
vector<string> answer;
for(int i=0; i< quiz.size(); i++){
stringstream ss(quiz[i]);
int a,b,c;
char ch1,ch2;
while(ss >> a >> ch1 >> b >> ch2 >> c){
if(ch1 == '-'){
if(c == a-b) answer.push_back("O");
else answer.push_back("X");
}
else{
if(c == a+b) answer.push_back("O");
else answer.push_back("X");
}
}
}
return answer;
}
입력받는 문자열은 숫자, "+" or "-", 숫자, "=", 숫자 순으로 되어있기 때문에 stringstream을 사용해 각각의 변수에 저장시켜 주었다.
반응형