Remove character
Remove character
Send Feedback
Remove character
The first line of input contains a string without any leading and trailing spaces.
The second line of input contains a character(X) without any leading and trailing spaces.
The only line of output prints the updated string.
You are not required to print anything explicitly. It has already been taken care of.
0 <= N <= 10^6
Where N is the length of the input string.
Time Limit: 1 second
aabccbaa
a
bccb
xxyyzxx
y
xxzxx
void removeAllOccurrencesOfChar(char input[], char c) {// Write your code hereint k=0;for(int i=0;input[i]!='\0';i++){if(input[i]!=c) input[k++]=input[i];}input[k]='\0';}
#include <iostream>#include <cstring>using namespace std;
void removeAllOccurrencesOfChar(char input[], char c) { // Write your code here int k=0; for(int i=0;input[i]!='\0';i++){ if(input[i]!=c) input[k++]=input[i]; } input[k]='\0';}
int main() { int size = 1e6; char str[size]; cin.getline(str, size); char c; cin >> c; removeAllOccurrencesOfChar(str, c); cout << str;}
Comments
Post a Comment