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 the use of pragma in embedded c?
Linked lists -- can you tell me how to check whether a linked list is circular?
What is typeof in c?
You are to write your own versions of strcpy() and strlen (). Call them mystrcpy() and mystrlen(). Write them first as code within main(), not as functions, then, convert them to functions. You will pass two arrays to the function in the case of mystrcpy(), the source and target array.
Why is c called a mid-level programming language?
What is the condition that is applied with ?: Operator?
What is boolean in c?
I was asked to write a program in c which when executed displays how many no.of clients are connected to the server.
What is volatile variable how do you declare it?
Is c weakly typed?
Q.1 write aprogram to stack using linklist o insert 40 items? Q.2 write a program to implement circular queue with help of linklist?
Write a program for finding factorial of a number.
Why does everyone say not to use scanf? What should I use instead?
Do you know the use of fflush() function?
What are dangling pointers in c?