View Code of Problem 114

#include<stdio.h>
#include<string.h>
int isalph(char c)
{
	if(c>='a'&&c<='z')
	return 1;
	else if(c>='A'&&c<='Z')
	return 1;
	return 0;
}
int main()
{
	char s[100],s2[100];
	gets(s);
	int len=strlen(s);
	int cnt=0;
	for(int i=0;i<len;++i)
	{
	
		if(!isalph(s[i]))
		{
			for(int j=i-1;j>=0&&isalph(s[j]);--j)
			{
				s2[cnt++]=s[j];	
			}
			while(!isalph(s[i]))
			{
				s2[cnt++]=s[i];
				i++;
			}
			--i;	
		}
	
	}
	if(isalph(s[len-1])){
	for(int j=len-1;j>=0&&isalph(s[j]);--j)
			{
				s2[cnt++]=s[j];	
			}
		}
		s2[cnt]='\0';
	printf("%s",s2);
}

Double click to view unformatted code.


Back to problem 114