Hdu 1062 Text Reverse !

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062

小结:水题,注意最后一行别输出空格就行!用到了栈这种数据结构! 

CODE:

#include<stdlib.h>
#include<stdio.h>
#include< string.h>
#include<stack>
using  namespace std;
 
stack< char> s;
const  int SIZE =  1001;
char sz1[SIZE];
char sz2[SIZE];
void output( char sz1[])
{
      int len = strlen(sz1);
      int i, j =  0;
      for(i =  0; i < len; i++)
     {
         s.push(sz1[i]);
     }
      while(!s.empty())
     {
         sz2[j++] = s.top();
         s.pop();
     }
     printf( " %s ", sz2);
}
 
int main()
{
      int t;
     scanf( " %d ", &t);
     getchar();
      while(t--)
     {
          int i, j= 0;
         memset(sz1,  0sizeof(sz1));
         memset(sz2,  0sizeof(sz2));
         gets(sz1);
          int len = strlen(sz1);
         sz1[len] =  '   ';
         sz1[len+ 1] =  ' \0 ';
          for(i =  0; i <= len; i++)
         {
              if(sz1[i] ==  '   ')
             {
              output(sz2);
              printf(i == len?  "": "   ");
              memset(sz2,  0sizeof(sz2)); 
              j =  0;
               continue;
             }
              else sz2[j++] = sz1[i];
         }
         printf( " \n ");
     }
      // system("pause");
      return  0;

} 

转载于:https://www.cnblogs.com/g0feng/archive/2012/04/22/2465369.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值