[hdu 1062] Text Reverse | STL-stack

The original title

Title effect:
T sets of data, each one line, speaking in front of a word space encountered inverted output.

Solution:
Obviously stack problem, the face of the current stack output empty spaces can be

#include<cstdio>
#include<stack>
#include<cstring>
using namespace std;
int t,l;
char s[1010];
stack <char> stk;

int main()
{
    scanf("%d",&t);
    getchar();
    while (t--)
    {
        gets(s+1);
        l=strlen(s+1);
        for (int i=1;i<=l;i++)
        {
            if (s[i]==' ')
            {
                while (!stk.empty())
                {
                    putchar(stk.top());
                    stk.pop();
                }
                putchar(' ');
            }
            else stk.push(s[i]);
        }
        while (!stk.empty())
        {
            putchar(stk.top());
            stk.pop();
        }
        putchar('\n');
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/mrha/p/11955100.html