1. 程式人生 > >杭電1062-Text Reverse

杭電1062-Text Reverse

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
const int MAX=101;
char s[MAX][MAX];
char k[MAX][MAX];
int p[MAX];
using namespace std;
int main()
{
    int t,n,i,j,a,b,q;
    while(cin>>t)
    {
        getchar();
        for(i=0;i<t;i++)
        {
            gets(s[i]);
            a=0;
            b=0;
            n=strlen(s[i]);
            for(j=0;j<n;j++)
            {
                if(s[i][j]==' ')
                {
                    p[a]=b;
                    a+=1;
                    b=0;
                }
                else
                {
                    k[a][b]=s[i][j];
                    b+=1;
                }
            }
            p[a]=b;
            for(q=0;q<=a;q++)
            {
                for(j=p[q]-1;j>=0;j--)
                {
                    cout<<k[q][j];
                }
                if(q!=a)
                cout<<' ';
            }
            cout<<endl;
        }
    }
    return 0;
}
/*-------------別人程式碼--------------------
#include<stdio.h>
#include<string.h>
int main()
{
  int t;
  scanf("%d\n",&t);
  while(t--)
  {
    char s[1005]={};
    while(scanf("%[^ \n]",s)!=EOF)
    {
      printf("%s",strrev(s));
      s[0]=0;
      putchar(getchar());
    }
  }
  return 0;
}
-------------------------------------------*/

坑啊!!!!