HDU:1062 Text Reverse

来源:互联网 发布:python 字符串替换代码 编辑:程序博客网 时间:2024/05/16 13:06
#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){    int n,j,i,k,n1;    char a[1000]={'\0'},b[1000]={'\0'};    while(scanf("%d",&n)!=EOF){        getchar();        for(k=0;k<n;k++){            gets(a);            j=-1;            n1=strlen(a);            for(i=0;i<n1;i++){                if(a[i]==' '){                    for(;j>=0;j--){                        printf("%c",b[j]);                    }                    printf(" ");                }else{                    b[++j]=a[i];                }            }            if(j!=-1)                for(;j>=0;j--)                    printf("%c",b[j]);            printf("\n");        }    }    return 0;}