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;

}

转载于:https://www.cnblogs.com/wuxi1995/p/4054970.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值