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
the process of defining something in terms of itself is called (or) in C it is possible for the functions to call themselves. A function called a) nested function b) void function c) recursive function d) indifinite function
What is the difference between a string and an array?
What does void main () mean?
What is 'bus error'?
Apart from dennis ritchie who the other person who contributed in design of c language.
Why clrscr is used in c?
What are terms in math?
How can I pad a string to a known length?
Explain how can I make sure that my program is the only one accessing a file?
Where we use clrscr in c?
What is the explanation for prototype function in c?
Can we increase size of array in c?
what value is returned to operating system after program execution?
Write a program on swapping (100, 50)
Explain built-in function?