View Code of Problem 114

#include<stdio.h>
#include<string.h>
int swap(int m,int n,char s[])
{
	int i;
	char temp;
	for(i=0;i<(n-m+1)/2;i++)
	{
	temp=s[i+m];
	s[i+m]=s[n-i];
	s[n-i]=temp;
	}
return 0;
}
int main()
{int i,k,a[1000],n,flag;
char c[1000],s,temp;
while(gets(c)!=NULL)
{n=strlen(c);
memset(a,0,sizeof(a));
k=1;flag=0;
a[0]=0;
for(i=1;i<n;i++)
{if(c[i]==' ')
{
	a[k++]=i;
	flag=1;
}}
if(!flag)
swap(0,n-1,c);
else
{swap(0,a[1]-1,c);
for(i=2;i<k;i++)
swap(a[i-1]+1,a[i]-1,c);
swap(a[k-1]+1,n-1,c);

}
printf("%s\n",c);
}
return 0;

}

Double click to view unformatted code.


Back to problem 114