Replace character in string c++
Line 1 : Input String S
Line 2 : Character c1 and c2 (separated by space)
Updated string
Constraints :
1 <= Length of String S <= 10^6
Sample Input :
abacd
a x
Sample Output :
xbxcd
c++ code:
void replaceCharacter(char input[], char c1, char c2) {
/* Don't write main().
* Don't read input, it is passed as function argument.
* No need to print or return the output.
* Change in the given input string itself.
* Taking input and printing output is handled automatically.
*/
if(input==nullptr) return;
for(int i=0; input[i] !='\0'; i++)
{
if(input[i]==c1)
{
input[i]=c2;
}
}
}
Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.
0 comments:
Post a Comment