473,395 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to delete duplicates in characters?

how to delete duplicates in characters?
output:
string:bnbhhgglk
result:nlk
Jul 12 '11 #1
5 4589
whodgson
542 512MB
string is an array
Expand|Select|Wrap|Line Numbers
  1. cout<<string;//prints bnbhhgglk
  2. string.erase(0,1);
  3. cout<<string;//prints nbhhgglk
  4. string.erase(1,5);
  5. cout<<string;//prints nlk 
hopefully!
Jul 12 '11 #2
how about
without
using erase???

what codes do I need to use without using erase or predefined functions???
Jul 12 '11 #3
weaknessforcats
9,208 Expert Mod 8TB
Rather than codE, what you need is an algorithm. Then you code the algorithm.

You might:
1) create an array of char big enough so there is one element for each letter..
2) read one character of your string.
3) Look in the array. The letter A has a value 65 so use element 65 for A's.
4) If the array element is blank, store the A there and output the character.
5) If the array element contains 65, then the A you have is a duplicate. Do not output the character.

Repeat all steps until input is processed.

Now start coding.

As a general rule: Only if you can write on paper in your own words what it is you want to do, can you code it.
Jul 12 '11 #4
whodgson
542 512MB
In my above post you cannot use string as a name as it is a reserve word. The string would have to be declared with something like string s ="bnbhhgglk". Clearly this is not the approach you want.
Jul 12 '11 #5
whodgson
542 512MB
One possible method would be:
1. create an array (say s) and populate it with lower case alphabet (a to z)
2. create a second array and initialize it with the string holding the duplicates.
3. with two nested loops compare s[0] with s1[0] -> s1[end] and count the number of s[0]`s in s1[].
4. if there is < 1 or > 1 instances of s[0] in s1[] type char(32) into s[0] otherwise do nothing.
5.zero the count and repeat for s[1] which holds 'b'
6.repeat until 'z' is reached.
7.print out the characters that are not spaces in the s[] array.
what follows provides an example of how the nested loops finds which lower case letters are not duplicated in the s1[]array.
Expand|Select|Wrap|Line Numbers
  1. for(int i=0;i<27;i++) 
  2.       {count=0;
  3.        for(int j=0;j<len;j++)
  4.         if(s[j]==s1[i])count++;
  5.         for(int j=0;j<len;j++) 
  6.         if(count<1||count>1)s1[i]= char(32);
  7.  
Jul 24 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Ragnorack67 | last post by:
Hello again, I have one further question about improving a validation. Currently this will validate a string of words separated by commas, and if it's greater than 9 will do something, or something...
11
by: steve smith | last post by:
Hi I'm still having some problems getting my head round this language. A couple of things don't seem to work for me. First I am trying to obtan a count of the number of words in a sting, so am...
2
by: Mamatha | last post by:
Hi I have an application with listview.When i click on one button the data will be displayed like this in the listview: colA colB colC ----- ----- ------...
6
by: pooh80133 | last post by:
Hi! I am pasting my SQL code at the end of this message. I am trying to use SELECT DISTINCT in a query, but I am a beginner for using Access. Right now I have duplicate ID's (Indiv ID) in my...
6
by: topala1984 | last post by:
hello all excuse my english, I`m a beginer in java and I want to remove duplicate cities + rearrenging file`s lines elements from one 150 mb file, in my file I have that: ...
8
natalie99
by: natalie99 | last post by:
hi everyone i have reseached this topic and cannot seem to find a solution that suits my problem, please help!! I have two tables, "Inventory" which contains 30,000 or so records, with about...
2
by: vlkc | last post by:
Hi, i have this database: 1 one 2 one people have 3 people one have 4 people have how can i remove duplicated rows with word "one" ?
5
by: rjonam | last post by:
What is the easiest way to remove duplicates from a XML file?
5
by: siebertp | last post by:
Hi I am unable to get the following code to work: def remove_duplicates (strng): """ >>> remove_duplicates ('apple') 'aple' >>> remove_duplicates ('Mississippi') 'Misp' ...
6
by: Mike Naz | last post by:
I have to write a program to demonstrate using bitmaps and bitwise operators to sort and remove duplicates from a file of random phone numbers. a lot of them... im not new to programming and i...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.