题目1525:子串逆序打印
#include <stdio.h>
#include<string.h>
#define MAX 100000+10
char s[MAX];
char tmp[MAX];
int main() {
int n;
while(~scanf("%d",&n))
{
if(n==0)return 0;
while(getchar()!='\n')
;
gets(s);
int len=strlen(s);
int i=0;
while(i<len)
{
int j=0;
while(i<len&&s[i]==' ')
{
i++;
j++;
}
if(j>0)
printf(" ");
j=0;
while(i<len&&s[i]!=' ')
{
tmp[j++]=s[i];
i++;
}
if(j>0)
{
for(int p=0,q=j-1;p<q;++p,--q)
{
char t=tmp[p];
tmp[p]=tmp[q];
tmp[q]=t;
}
tmp[j]='\0';
printf("%s",tmp);
}
}
printf("\n");
}
return 0;
}
/**************************************************************
Problem: 1525
User: kirchhoff
Language: C
Result: Accepted
Time:40 ms
Memory:1112 kb
****************************************************************/