-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest3.cpp
More file actions
36 lines (26 loc) · 821 Bytes
/
test3.cpp
File metadata and controls
36 lines (26 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Given a string and a character, remove all the occurrences of the character in the string
#include <bits/stdc++.h>
using namespace std;
void removeOccurancesofCh(string str, char ch) {
string ans = "";
for(int i =0; i<str.length(); i++) {
if(str[i] != ch) {
ans = ans + str[i];
}
}
cout<<ans<<endl;
}
int main()
{
vector<pair<string, char>> arr;
arr.push_back(make_pair("helloworld", 'h'));
arr.push_back(make_pair("helloworld", 'w'));
arr.push_back(make_pair("helloworld", 'e'));
arr.push_back(make_pair("helloworld", 'o'));
arr.push_back(make_pair("helloworld", 'd'));
arr.push_back(make_pair("helloworld", 'l'));
for(int i = 0; i<arr.size(); i++) {
removeOccurancesofCh(arr[i].first, arr[i].second);
}
return 0;
}