ACM (TJU) : 1153


// http://acm.tju.edu.cn/toj/showp1153.html

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

void reverse (char x [])
{
    int length = strlen (x);

    for ( int i = 0; i < length / 2; i++ )
        swap (x [i], x [length - 1 - i]);

    printf ("%s", x);
}

int main ()
{
    int dataset;
    scanf ("%d", &dataset);
    getchar ();

    while ( dataset-- ) {
        char a [10000];
        gets (a);

        char word [1000];
        int index = 0;

        for ( int i = 0; a [i] != 0; i++ ) {
            if ( a [i] == ' ' ) {
                word [index] = 0;
                reverse (word);
                index = 0;
                printf (" ");
            }

            else
                word [index++] = a [i];
        }

        word [index] = 0;
        reverse (word);
        printf ("\n");
    }

    return 0;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s