/* 功能Function Description:     将字符串中的每个单词中的字符逆转 TOJ-1153
   开发环境Environment:          DEV C++ 4.9.9.1
   技术特点Technique:
   版本Version:
   作者Author:                   可笑痴狂
   日期Date:                 	 20120801
   备注Notes:
   题目来源:
   http://acm.tju.edu.cn/toj/showp1153.html
*/

#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main()
{
	int n,i,j,len,st,k;
	char t;
	char s[1000];
	scanf("%d",&n);
	getchar();
	while(n--)
	{
		st=0;
		gets(s);
		len=strlen(s);
		i=-1;
		while(!isalpha(s[++i]));  //消除字符串开始的空格
		st=i;
		for(;i<=len;++i)
		{
			if(!isalpha(s[i]))
			{
				k=1;
				for(j=st;j<=(st+i-1)/2;++j)
				{
					t=s[j];
					s[j]=s[i-k];
					s[i-(k++)]=t;
				}
				while(!isalpha(s[++i]));
				st=i;
			}

		}
		puts(s);
	}
	return 0;
}

 

posted on 2012-08-01 10:31  可笑痴狂  阅读(371)  评论(0编辑  收藏  举报