fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <stack>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main(void) {
  9. ios_base::sync_with_stdio(0);
  10. cin.tie(0);
  11. cout.tie(0);
  12.  
  13. int t; cin >> t;
  14. cin.ignore();
  15. string temp;
  16. stack<char> stk;
  17. vector<char> vtr;
  18.  
  19. for (int i = 0; i < t; ++i) {
  20. getline(cin, temp);
  21. for(int j=0; j<temp.size(); ++j) {
  22. if (temp[j] == ' ') {
  23. while ( !( stk.empty() ) ) {
  24. vtr.push_back(stk.top());
  25. stk.pop();
  26. }
  27. vtr.push_back(temp[j]);
  28. continue;
  29. }
  30. else {
  31. stk.push(temp[j]);
  32. }
  33. }
  34. while (!(stk.empty())) {
  35. stk.pop();
  36. }
  37. for (auto k : vtr) cout << k;
  38. cout << "\n";
  39. vtr.clear();
  40. }
  41.  
  42.  
  43.  
  44.  
  45. }
Success #stdin #stdout 0s 4176KB
stdin
3
hello motoro
tt oo
ddd fff
stdout
olleh 
tt 
ddd