解题思路: 利用栈的先入后出(FILO)的特点,将string中的字符顺序压入栈中,然后将字符一个个输出之后弹出即可。输出时注意条件判断 while(!car.empty()), 即 car非空。

#include<bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    stack<char> car;

    getline(cin, s);
    for(int i=0; i<s.length(); i++)
        car.push(s[i]);

    while(!car.empty())
    {
        cout << car.top();
        car.pop();
    }
}