1062 字符串处理 水题

来源:互联网 发布:编程常用语言有哪些 编辑:程序博客网 时间:2024/05/22 02:24
Hot~~欢迎“信息学(OI)选手”——报考杭州电子科技大学!Text ReverseTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25889    Accepted Submission(s): 10041Problem DescriptionIgnatius 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.InputThe 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.OutputFor each test case, you should output the text which is processed.Sample Input3olleh !dlrowm'I morf .udhI ekil .mcaSample Outputhello world!I'm from hdu.I like acm.HintRemember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.AuthorIgnatius.LRecommend
#include<stdio.h>#include<string.h>char c[1001];void print(int n){    for(int i=1;i<=n;i++)    {        gets(c);//puts(c);        int len=strlen(c);        for(int i=0;i<len;i++)        {            if(c[i]==' ')            {                for(int j=i-1;c[j]!=' '&&j>=0;j--) putchar(c[j]);                putchar(' ');            }            if(i==len-1) for(int j=i;c[j]!=' '&&j>=0;j--) putchar(c[j]);        }     putchar('\n');    }}int main(void){    //freopen("E:\\test.txt","r",stdin);    int n;    while(~scanf("%d",&n))    {        getchar();        print(n);    }    return 0;}
0 0
原创粉丝点击