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
What is a protocol in c?
How we can insert comments in a c program?
What is string constants?
All technical questions
What is maximum size of array in c?
write a c program thal will find all sequences of length N that produce the sum is Zero, print all possible solutions?
How does normalization of huge pointer works?
What is #ifdef ? What is its application?
What is the difference between a free-standing and a hosted environment?
in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.
hi friends how r u as soon in satyam my interview is start but i m very confusued ta wat i do plz help me frndz wat can i do plz tell me some question and answers related with "C" which r asked in the interview .
Not all reserved words are written in lowercase. TRUE or FALSE?
Who developed c language?
Synonymous with pointer array a) character array b) ragged array c) multiple array d) none
When should you not use a type cast?