Duplicate removal

R

raja

Design and implement an efficient algorithm to remove consecutive
1char, 2char, 3 char... so on recurrences in dictionary words.
For example, "abbabccbc" first will become "ababcbc", then become
"abc". Similarly, "abcaab" will become "abcab" and but stays as it is
after that.
 
K

Keith Thompson

raja said:
Design and implement an efficient algorithm to remove consecutive
1char, 2char, 3 char... so on recurrences in dictionary words.
For example, "abbabccbc" first will become "ababcbc", then become
"abc". Similarly, "abcaab" will become "abcab" and but stays as it is
after that.

And why exactly would we want to do that?

This looks like a homework assignment. If so, try to solve the
problem yourself; if you run into trouble, show us what you have and
exactly what problems your having, and we might be able to give you
some hints.

Either that, or give us your instructor's e-mail address so we can
submit our solutions directly.
 
M

Malcolm

raja said:
Design and implement an efficient algorithm to remove consecutive
1char, 2char, 3 char... so on recurrences in dictionary words.
For example, "abbabccbc" first will become "ababcbc", then become
"abc". Similarly, "abcaab" will become "abcab" and but stays as it is
after that.
Start by specifying the problem as a function.

/*
remove consecutive repeated characters from a string
Parmas: dest - pointer to destination
src - source string
*/
void removerepeats(char *dest, const char *src)

The algorithm should be pretty trivial to write. You just need one pass
through the source string.

Once you have written the function, test it, and then apply it to your
problem.
 
T

Thad Smith

raja said:
Design and implement an efficient algorithm to remove consecutive
1char, 2char, 3 char... so on recurrences in dictionary words.
For example, "abbabccbc" first will become "ababcbc", then become
"abc". Similarly, "abcaab" will become "abcab" and but stays as it is
after that.

Before you do that, consider whether it makes a difference in what
order the replacements are done. If so, what order will you do them?
If not, can you prove it?
 
A

Arndt Jonasson

raja said:
Design and implement an efficient algorithm to remove consecutive
1char, 2char, 3 char... so on recurrences in dictionary words.
For example, "abbabccbc" first will become "ababcbc", then become
"abc". Similarly, "abcaab" will become "abcab" and but stays as it is
after that.

I'm probably unusually thick this morning, but I don't understand the
specification.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top