Text Reverse
思路:这道题就是一个字符串反转的问题,可以考虑使用栈的性质,先进后出,来完成这道题
代码:
#include<iostream> #include<stack> using namespace std; int main(){ int n; char ch; while (cin >> n){ getchar(); while (n--){ stack<char> str; while (1){ ch = getchar(); if (ch == ' ' || ch == ' ' || ch == EOF){ while (!str.empty()){ cout << str.top(); str.pop(); } if (ch == ' ' || ch == EOF){ break; } cout << " "; }else str.push(ch); } cout << endl; } } system("pause"); return 0; }