综合训练(1)+字符串

 

H - Text Reverse

#include<iostream>
#include<stack>
#include<stdio.h>
using namespace std;
char c;
int n;
int main()
{
    stack<char> s;
    scanf("%d",&n);getchar();
    while(n--)
    {
        while(1)
        {
            c=getchar();
            if(c==' '||c=='\n')
            {
                while(!s.empty())
                {
                    printf("%c",s.top());
                    s.pop();
                }
                cout<<c;
            }
            else
            {
                s.push(c);
            }
            if(c=='\n') break;
        }
    }
}

  

猜你喜欢

转载自www.cnblogs.com/chrysanthemum/p/12682350.html