Enter a string, remove consecutive duplicate characters
Example:
Enter a string: ohhello
After removing consecutive duplicate characters: ohelo
Base code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
int i, j;
cout << "Enter a string: ";
cin >> str;
for (i = 0; i < str.length(); i++) {
// check if str[i] is same as str[i+1]
// if same, remove str[i+1] by shifting all characters to the left
}
}
Use function to remove all duplicate characters from a string
Example:
Enter a string: ohhello
Unique characters: ohelo
Base code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
int i, j, k;
cout << "Enter a string: ";
cin >> str;
for (i = 0; i < str.length(); i++) {
// for each characters
for (j = i + 1; j < str.length(); j++) {
// check the rest of the characters if same as str[i]
// if same, remove str[j] by shifting all characters to the left
}
}
}