Want logic or code for this in c
-
Hello All, I am new with c!! Can anybody give me the code for following result Input:aababba Output:a2bab2a Its like encrypt given value. Thanks in advance.
Well since it would appear to be RLE [Run Length Encoding], I would google for that.
-
Hello All, I am new with c!! Can anybody give me the code for following result Input:aababba Output:a2bab2a Its like encrypt given value. Thanks in advance.
here is an algorithm that should do it, in pseudo-code:
char prev=0;
int count=0;
foreach(char c in the input) {
if (c!=prev) {
if (count>1) output(count);
output(c);
prev=c;
count=0;
}
count++;
}It is a bit tricky, I suggest you study it first (test it by hand!), then implement it in C and test it again. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Well since it would appear to be RLE [Run Length Encoding], I would google for that.
-
here is an algorithm that should do it, in pseudo-code:
char prev=0;
int count=0;
foreach(char c in the input) {
if (c!=prev) {
if (count>1) output(count);
output(c);
prev=c;
count=0;
}
count++;
}It is a bit tricky, I suggest you study it first (test it by hand!), then implement it in C and test it again. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
Well, you're always right: after all,
C#
code is pseudo-code. ;PIf the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Well, you're always right: after all,
C#
code is pseudo-code. ;PIf the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]CPallini wrote:
you're always right
:rose:
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.