공백포함 문자열 입력과 그 입력된 문자열을 벡터에 구분해서 넣는 법에 대해 공부했다.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
void input_test(vector<string>& T)
{
int i, t;
cin >> t;
cin.ignore();
for (i = 0; i < t; i++)
{
string str;
getline(cin, str);
T.push_back(str);
}
return;
}
void find_answer(vector<string>& T)
{
int i, j;
for (i = 0; i < T.size(); i++)
{
stack <char> temp;
for (j = 0; j < T[i].length(); j++)
{
if (T[i][j] == ' ')
{
while (!temp.empty())
{
cout << temp.top();
temp.pop();
}
cout << " ";
}
else
{
temp.push(T[i][j]);
}
}
while (!temp.empty())
{
cout << temp.top();
temp.pop();
}
cout << "\n";
}
return;
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vector<string> T;
input_test(T);
find_answer(T);
return 0;
}