杭电 -- 1062 解法二

#include<stdio.h>
#include<string.h>
#define MaxSize 1000

void reverse(char arr[]){
    char tmp[MaxSize];
    int i,j,k;
    for(i=0,j=0;i<strlen(arr);i++){
        tmp[j++] = arr[i];
        if(arr[i]==' '){
            for(k=j-2;k>=0;k--){
                printf("%c",tmp[k]);
            }
            printf("%c",tmp[j-1]);
            j = 0;
        }
    }
    
    for(i=j-1;i>=0;i--){
        printf("%c",tmp[i]);
    }
}

int main(){
    int loop = 0;
    scanf("%d",&loop);
    //get the '\n'
    getchar();
    char arr[MaxSize];
    while(loop--){
        gets(arr);
        reverse(arr);
        printf("\n");
    }
    return 0;
}

这种为什么没有报上一篇的错!通过了!有点懵了!

猜你喜欢

转载自www.cnblogs.com/kyrie211/p/11087600.html