颠倒文本,求助。
Sample Input
olleh !dlrow
m'I morf .udh
I ekil .mca
Sample Output
hello world!
I'm from hdu.
I like acm.
这我写的代码,不知为何在OJ系统上AC不了。还有没有更好的写法?
#include <stdio.h>
int main ()
{
char a[101];
int i=0,j=0;
gets(a);
while (a[i]!='\0')
{
if (a[i]==' ')
{ j=i-1;
while (a[j]!=' ')
{printf ("%c",a[j]);
if (j==0)
break;
j--;
}
printf (" ");
}
i++;
}
i=i-1;
while (a[i]!=' ')
{
printf ("%c",a[i]);
i--;
}
printf ("\n");
return 0;
}
[解决办法]