1009 ironic (20 points)

Given a word of English, asking you to write a program, all the words of the sentence order reversed output.

Input format:
test input comprising a test case, given the string length does not exceed a total of 80 in a row. String composed of several words and a number of spaces, where the word is English letters (case is case) consisting of string, separated by a space between words, the input end of the sentence to ensure that no extra space.

Output format:
each test case output per line, output sentence after the reverse.

Sample input:
the Hello World Here Come the I

Sample output:
Come the I Here the Hello World

algorithms:
speak each word push into the stack inside, as long as the stack is not empty, it has been pop, cmd inside the test finished, press ctrl + z input

#include <iostream>
#include <stack>

using namespace std;

stack<string> stk;

int main()
{
    string s;
    while(cin >> s)
        stk.push(s);
    cout << stk.top();
    stk.pop();
    while(!stk.empty())
    {
        cout << ' ' << stk.top();
        stk.pop();
    }

    return 0;
}

Guess you like

Origin blog.csdn.net/qq_42549254/article/details/93397741