What is Duplicate Characters?
Duplicate Character means repeating characters.
In these program we will remove the characters that are present more than once.
Program:
#include <iostream> using namespace std; int main() { string s = "Scrupulously"; for(int i = 1; i < s.length(); i++) { for(int j = 0; j < i; j++) { if(s[j] == s[i]) {
//erase is an inbuilt function used to erase char of given index
s.erase(i,1); i--; } } } cout << s << endl;; return 0; }
Output:
Scruplosy
Learn more about string here.
C++ Program To Remove Duplicate Characters From Given String
Reviewed by Beast Coder
on
March 26, 2021
Rating:
No comments: