-
문제를 끝까지 읽어볼 필요가있고 예제 입출력을 한번더 볼필요가있었던문제,
내가 난독증이있는지는 모르겠지만, 그냥 처음에 문자를 아예거꾸로 뒤집는줄알았다.
그게아니여서 처음에 스택을 쓰다가 큐로바꿨고 굉장히 무난하게 푼 문자열문제
#include<iostream> #include<queue> #include<string> #include<cstdio> #include<stack> using namespace std; int main() { int n; cin >> n; queue<string> x; string a; getline(cin, a); for (int i = 0; i < n; i++) { getline(cin, a); //cout << a; string temp; for (int i = 0; i < a.length(); i++) { if (a[i] != ' ') { temp += a[i]; //cout << temp << endl; } if (i == a.length() - 1) { x.push(temp); temp = ""; } else if(a[i] == ' '){ //cout << "push" << endl; x.push(temp); temp = ""; } } while (!x.empty()) { for (int i = x.front().length() - 1; i >=0 ; i--) { cout << x.front()[i]; } cout << " "; x.pop(); } cout << "\n"; } return 0; }