ACM step 1.2.2 Text Reverse

 

gnatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.

 

一个简单的回文输出。。然后请原谅我的冗长的代码,之前很久没写程序了。。

//

//  main.cpp

//  hdu1.2.2

//

//  Created by wuxi on 14-10-22.

//  Copyright (c) 2014年 wuxi. All rights reserved.

//

 

#include <iostream>

#include <cstring>

#include <cstdio>

int T,num=0;

char a;

char b[10000];

void add(char c)

{

    

    for (int i=0;i<=10000;i++)

        if (b[i]=='\0')

        {

            b[i]=c;

            num++;

            break;

        }

}

void print()

{

    

    for (int i=num-1;i>=0;i--)

        printf("%c",b[i]);

    num=0;

    memset(b,0,sizeof(b));

}

int main() {

    memset(b,0,sizeof(b));

    scanf("%d",&T);

   getchar();

    while (T--)

    {

      while(scanf("%c",&a)!=EOF)

       {

         

           if (a==' ')

           {

               print();

               printf(" ");

           }

           else if (a=='\n')

           {

            print();

            putchar('\n');

            break;

           }else add(a);

       }

        

    }

    //print();

    return 0;

}

posted @ 2014-10-27 19:41  蔚然成风  阅读(172)  评论(0编辑  收藏  举报