-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMove All X At End.cpp
49 lines (43 loc) · 1.06 KB
/
Move All X At End.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Hacker Blocks */
/* Title - Move All X At End */
/* Created By - Akash Modak */
/* Date - 14/07/2020 */
// Take as input str, a string. Write a recursive function which moves all ‘x’ from the string to its end.
// E.g. for “abexexdexed” return “abeedeedxxx”.
// Print the value returned
// Input Format
// Single line input containing a string
// Constraints
// Length of string <= 1000
// Output Format
// Single line displaying the string with all x's moved at the end
// Sample Input
// axbxc
// Sample Output
// abcxx
// Explanation
// All x's are moved to the end of string while the order of remaining characters remain the same.
#include <bits/stdc++.h>
using namespace std;
void moveatend(char *inp, int i, int l)
{
if(i>=l){
return;
}
char x=inp[i];
if(x!='x'){
cout<<x;
}
moveatend(inp,i+1,l);
if(x=='x'){
cout<<x;
}
return;
}
int main() {
char inp[10001];
cin>>inp;
int l = strlen(inp);
moveatend(inp,0,l);
return 0;
}