Replace Character
Given an input string S and two characters c1 and c2, you need to replace every occurrence of character c1 with character c2 in the given string.
Input Format :
Output Format :
Constraints :
1 <= Length of String S <= 10^6
Sample Input :
Sample Output :
#include <iostream>
#include <cstring>
using namespace std;
#include "solution.h"
int lenght(char str[]){
int count=0;
for (int i=0;str[i]!='\0';i++){
count++;
}
return count;
}
void replaceCharacter(char input[], char c1, char c2) {
// Write your code here
for(int i=0;i<lenght(input);i++){
if(input[i]==c1){
input[i]=c2;
}
}
}
int main() {
char input[1000000];
char c1, c2;
cin >> input;
cin >> c1 >> c2;
replaceCharacter(input, c1, c2);
cout << input << endl;
}
Comments
Post a Comment