wheel algo

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ykumawat789
    New Member
    • Feb 2017
    • 1

    wheel algo

    how we split a string like


    if string is even (abcdef) then print afbecd
    or string is odd (abcde) then print aebde@
  • husoski
    New Member
    • Feb 2017
    • 4

    #2
    I assume you meant "aebdc@" in your odd example. If so, then you can repeatedly remove the first and last characters from the input string, adding them to the output string in that order, until the length of the remaining string is less than 2.

    Then, if there's a character remaining at the end (length is 1, not 0) then append it to the end of your output string, followed by a '@'.

    It's been 15+ years since I've done anything at all in VB6, and I don't remember the syntax well enough to offer a working code snippet, but that idea will work with any language that has strings with concatenation and a substring function or method.
    Last edited by husoski; Feb 27 '17, 02:54 PM. Reason: spelling error

    Comment

    • codegazer
      New Member
      • Oct 2015
      • 27

      #3
      I presume your odd/even refers to the length of the string.
      If so, this will work.

      Code:
      if len(yourstring)\2 = 0 then       'even number
          print "abcdef"
      else
          print "aebde@
      end if
      Last edited by codegazer; Feb 27 '17, 07:13 PM. Reason: punctuation

      Comment

      Working...