Move X at end - Help

#include
using namespace std;

void movex(char *a)
{
if(a[0] == ‘\0’)
{
return;
}

if(a[0] == 'x')
{
	int i=0;
	while(a[i]!='\0')
	{
		a[i] = a[i+1];
		i++;
	}
	a[i-1] = 'x';

	movex(a);
}

movex(a+1);

}
int main() {
char a[1000];
cin>>a;

movex(a);

cout<<a;

return 0;

}

hey @abhishekchoudhary there are couple of small mistakes in your code

  1. you need to compare a[i+1] with ‘\0’ instead of a[i]
  2. you need to replace a[i] in the end instead of a[i-1]
  3. if you replace with ‘x’ you’ll get TLE instead replace with X and then replace X with x in your solution
    Here is the code for the same
    https://ide.codingblocks.com/s/197085
1 Like