字符串反转

时间:2025-04-04 09:50:54
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
  
  
char a[1005];
int main()
{
    int N;
    cin>>N;
    getchar();
    while(N--)
    {
        gets(a);
        int len=strlen(a);
        a[len]='\0';
        int i,j,k;
        j=-1;
        for(i=0;i<=len;i++)
            {
                if(a[i]==' '||a[i]=='\0')
                {
                    for(k=i-1;k>j;k--)
                      printf("%c",a[k]);
                    if(a[i]!='\0')
                        printf(" ");
                   j=i;
                }
            }
            printf("\n");
    }
    return 0;
  
}
  
  
/**************************************************************
    Problem: 1819
    User: 031640209
    Language: C++
    Result: Accepted
    Time:7 ms
    Memory:1692 kb
****************************************************************/