공백포함한 문자열을 받고, 공백 기준으로 파싱하는 함수를 공부할 수 있었다. 공백기준 문자열 파싱에 대해 따로 정리하겠다.
참고 : https://seoyeonkk.tistory.com/entry/C-%EA%B3%B5%EB%B0%B1-%EA%B8%B0%EC%A4%80-%EB%AC%B8%EC%9E%90%EC%97%B4-%EC%9E%90%EB%A5%B4%EA%B8%B0split
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;
void input_data(vector<stack<string>>& data)
{
int n, i;
string temp;
cin >> n;
cin.ignore();
for (i = 0; i < n; i++)
{
getline(cin, temp);
stringstream ss(temp);
stack <string> reverse_word;
string word;
while (ss >> word)
{
reverse_word.push(word);
}
data.push_back(reverse_word);
}
return;
}
void find_answer(vector<stack<string>>& data)
{
int i;
for (i = 0; i < data.size(); i++)
{
cout << "Case #" << i + 1 << ": ";
while (!data[i].empty())
{
cout << data[i].top() << " ";
data[i].pop();
}
cout << "\n";
}
return;
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vector <stack<string>> data;
input_data(data);
find_answer(data);
return 0;
}