Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
784 views
in Online Assessments by Expert (108,280 points) | 784 views

1 Answer

0 like 0 dislike

problem Statement: Write a function that will accept a string whose length is “len”, the string has some “#” keywords in it. Now move all the hashes ‘#’ to the front of the string and return the whole string back and last print it.

Sample Test Case:

Input: The#Learn#Programo

Output: ###TheLearnProgramo

Program in C++:

//Learnprogramo - programming made simple
#include<bits/stdc++.h>
using namespace std;
char *moveHash(char str[], int len) 
{
//Initilizing the required variables
char result[100], resultHash[100];
int j=0, k=0, i;
//Iterate on string
for(i=0; i<len; i++) 
{
//If hash found then adding # keyword in resultHash string and continue the loop
if(str[i] == '#') {
resultHash[k] = '#';
k++;
continue;
}//if..
//Here means not '#' char so adding original in result
result[j] = str[i];
j++;
}//for...
//Print
cout<<resultHash<<result;
}
int main() 
{
//Initilizing the required variables
char str[100];
int len;
//Input
cin>>str;
//Calculating length of string
len = strlen(str);
moveHash(str, len);
}
by Expert (108,280 points)