CUIT 2016 新生训练题第一周 D-Text Reverse

来源:互联网 发布:linux时钟同步设置 编辑:程序博客网 时间:2024/05/18 01:46

Text Reverse

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 25   Accepted Submission(s) : 13
Problem Description
Ignatius 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.
 

Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains a single line with several words. There will be at most 1000 characters in a line.
 

Output
For each test case, you should output the text which is processed.
 

Sample Input
3olleh !dlrowm'I morf .udhI ekil .mca
 

Sample Output
hello world!
I'm from hdu.
Ilike acm.
[hint]Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.

[/hint]




#include<string.h>#include<stdio.h>int main(){    int i,N,len,j,k,t;    char a1[1000],a2[100];    scanf("%d",&N);    getchar();    while(N--)    {        gets(a1);        len=strlen(a1);        for(i=0,j=0,t=0;i<len;i++)        {            if(a1[i]!=' ' )                a2[j++]=a1[i];            else            {                if(t>0)                    printf(" ");                for(k=j-1;k>=0;k--)                    printf("%c",a2[k]);                j=0;                t++;            }            if(i==len-1)            {                printf(" ");                for(k=j-1;k>=0;k--)                    printf("%c",a2[k]);            }        }        printf("\n");    }    return 0;}


0 0