题解 | 句子逆序
#include <iostream> #include <string> #include <stack> using namespace std; int main() { string a; getline(cin, a); int pos = a.find(' ', 0); stack<string> stks; while (-1 != pos){ string b = a.substr(0, pos); stks.push(b); a.erase(0, pos+1); pos = a.find(' ', 0); } if (a.length() > 0) { stks.push(a); } while (!stks.empty()) { cout << stks.top() << " "; stks.pop(); } } // 64 位输出请用 printf("%lld")