View Code of Problem 114

#include  <stdio.h>
#include  <stdlib.h>
#include  <math.h>
#include  <string.h>
// works for tomorrow
int main()
{
	char s[1000];
	char t;
	int i,j,n,top=0;

	while (gets(s)!=NULL)
	{
		char *p=s;
		for (n=0,i=-1,j=-1;*p!='\0';p++,n++)
		{
			if(isalpha(*p))
			{
				if(i==-1) i=n;
			}
			else
			{
				if(i>=0)
				{
					j=n-1;
					// change
					for (;i<j;i++,j--)
					{
						t=s[i];s[i]=s[j];s[j]=t;
					}
					i=-1;j=-1;
				}
			}
		}
		if(i>=0&&i<=n)
		{
			j=n-1;
			// change
			for (;i<j;i++,j--)
			{
				t=s[i];s[i]=s[j];s[j]=t;
			}
			i=-1;j=-1;
		}
		printf("%s\n",s);
	}

	return 0;	
}

Double click to view unformatted code.


Back to problem 114