Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Want logic or code for this in c

Want logic or code for this in c

Scheduled Pinned Locked Moved C / C++ / MFC
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KIDYA
    wrote on last edited by
    #1

    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.

    C L 2 Replies Last reply
    0
    • K KIDYA

      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.

      C Offline
      C Offline
      CodyDaemon
      wrote on last edited by
      #2

      Well since it would appear to be RLE [Run Length Encoding], I would google for that.

      K 1 Reply Last reply
      0
      • K KIDYA

        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.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        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.

        CPalliniC 1 Reply Last reply
        0
        • C CodyDaemon

          Well since it would appear to be RLE [Run Length Encoding], I would google for that.

          K Offline
          K Offline
          KIDYA
          wrote on last edited by
          #4

          Thank you.I got code for same on google!!

          1 Reply Last reply
          0
          • L Luc Pattyn

            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.

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            Well, you're always right: after all, C# code is pseudo-code. ;P

            If 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]

            In testa che avete, signor di Ceprano?

            L 1 Reply Last reply
            0
            • CPalliniC CPallini

              Well, you're always right: after all, C# code is pseudo-code. ;P

              If 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]

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups