Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Why do some versions of toupper act strangely if given an upper-case letter?

1033


What are the 4 data types?

959


what are the 10 different models of writing an addition program in C language?

1839


There seem to be a few missing operators ..

1001


Why is a semicolon (;) put at the end of every program statement?

1028


Difference between Shallow copy and Deep copy?

1967


What is the purpose of type declarations?

1072


What does s c mean in text?

1053


Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.

1045


Why c is called free form language?

965


What happens if a header file is included twice?

982


Find duplicates in a file containing 6 digit number (like uid) in O (n) time.

3181


What are the two forms of #include directive?

1098


int i=10; printf("%d %d %d", i, i=20, i);

1547


Explain the difference between #include "..." And #include <...> In c?

980