hdu 1062 Text Reverse (STL栈)

#include<stdio.h>
#include<stack>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
    int T;
    char a[1005];
    int al;
    stack<char> s;
    scanf("%d",&T);
    getchar();
    for(int i=0;i<T;i++)
    {
        gets(a);
           al=strlen(a);
           a[al]=' ';
           for(int j=0;j<=al;j++)
           {
               if(a[j]!=' ')s.push(a[j]);
               else
               {
                   while(!s.empty())
                   printf("%c",s.top()),s.pop();
                   //printf(" ");
                   if(j!=al)printf("%c",a[j]);
               }
           }
           printf("\n");
    }
    return 0;
}

##直接输出空格会产生 格式错误

原文地址:https://www.cnblogs.com/XDJjy/p/3010191.html