write a c program to remove all the duplicate characters in a
string and replace with single character?
ex:-input- AAABBBCCC
output- ABC
Answer Posted / satya
//using the std::string class from namespace std.
#include<iostream>
using namespace std;
int main()
{
string myStr;
cout<<"enter new string.";
getline(cin,myStr);
cout<<"entered value is "<<myStr;
char ch;
bool m=false;
string newStr;
newStr.resize(1);
int k=0;
for(int i=0;i<myStr.length();i++)
{
ch=myStr[i];
for(int j=0;j<k+1;j++)
{
if(ch!=newStr[j]) m=false;
else { m=true; break;}
}
if(m==false)
{
newStr.resize(newStr.size()+1);
newStr[++k]=ch;
}
}
cout<<"\nAfter removing duplicate letters, string is "<<newStr;
}
Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
Explain the array representation of a binary tree in C.
Are negative numbers true in c?
What is a #include preprocessor?
What are the types of unary operators?
What is gets() function?
What does *p++ do? What does it point to?
Hi how many types of software editions are there and their difference (like home editions, enterprise, standard etc) can u please help me
Why isnt any of this standardized in c?
What does struct node * mean?
FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above
I need testPalindrome and removeSpace
#include
What are nested functions in c?
Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant
Simplify the program segment if X = B then C ← true else C ← false
What is New modifiers?