#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#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 init;
ss >> init;
char a, c;
int b, d;
while (ss >> a >> b >> c >> d)
{
if (a == '+')
{
init += b;
if (init == d) answer.push_back("O");
else answer.push_back("X");
}
else if (a == '-')
{
init -= b;
if (init == d) answer.push_back("O");
else answer.push_back("X");
}
}
}
return answer;
}
int main()
{
vector<string> quiz = {"19 - 6 = 13", "5 + 66 = 71", "5 - 15 = 63", "3 - 1 = 2"};
solution(quiz);
}
메인함수 arr의 7 - 3 = 11 에서 11을 저기 물음표 친 부분에 할당하고싶으면 여기서 어떻게 해야하죠 ..?
이렇게 해봤어요.
https://www.online-cpp.com/jWuqJVbMOP
좀 전에 해결하긴 했는데 ( 19 - 6 = 13 ) 에서 19를 init , - 에 char a, 6을 int b, =에 char c, 13을 int d 이런식으로 넣고 하는건 별론가요 ?
그리고 =를 받은 c는 while문 안에 쓰지 않는 방식으루,,
본문 코드 수정했어요
해결했다니 안되는 것은 아니겠지만, 링크에 걸린 코드는 "7 - 3 + 3 + 4 = 11" 이런 식으로도 가능함.
"7, - 3 + 3 + 4 + 5 + 6 + 7 = 29" 이런 식으로 확장 가능
위에 쉼표(,)는 오타.ㅎㅎ
감사합니당