Skip to content

Commit 25b912e

Browse files
authored
Move All X At End
1 parent a74e50b commit 25b912e

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

Hacker Blocks/Move All X At End.cpp

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

0 commit comments

Comments
 (0)