Results 1 to 12 of 12
  1. #1
    varma is offline Member
    Join Date
    Jan 2010
    Posts
    1
    Rep Power
    0

    Default Need some help ASAP

    Hi i need some help in creating this program,




    Program, in a standard programming language (e.g. Java), a fast and simple solution to the following problem without using any regular expression or pattern matching utilities. Given a non-finite stream of characters, output an "A" if the characters "xxx" are found in exactly that sequence. If the characters "xMx" are found instead, output a "B". Do not re-process characters so as to output both an A and a B when processing the same input. For example:

    1. The following input xxMxMxxxMxxx would produce the following output: BAA

    2. The following input xxxMxMxxxxMMxMxMx would produce the following output: ABAB



    thanks in advance.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    This is what I was thinking: make a while loop that starts at the first char. Look at the first 3 chars. If they are equivalent to A or B result, move onto the 4th char. If they are not, move onto the 2nd character. Then compare the 2nd, 3rd, and 4th char. If they match, move onto the 5th char. If not, move onto the 3rd char and so on. Hope that helps. ;)

  4. #4
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

    Default

    You could also use patterns: Java Tutorials: Regex
    Last edited by collin389; 01-07-2010 at 03:12 AM.

  5. #5
    Kligham is offline Member
    Join Date
    Sep 2009
    Posts
    30
    Rep Power
    0

    Default

    Quote Originally Posted by collin389 View Post
    You could also use patterns: Java Tutorials: Regex
    He literally said:
    without using any regular expression or pattern matching utilities

  6. #6
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

    Default

    Oh, I didn't read his post... Just now noticed that he is getting input from an infinite stream of chars so he will have to use a buffer.

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by varma View Post
    Given a non-finite stream of characters, output an "A" if the characters "xxx" are found in exactly that sequence. If the characters "xMx" are found instead, output a "B". Do not re-process characters so as to output both an A and a B when processing the same input. For example:

    1. The following input xxMxMxxxMxxx would produce the following output: BAA

    2. The following input xxxMxMxxxxMMxMxMx would produce the following output: ABAB
    There is no way the first system produces that output. That is a Semi Thue System and has to obey the rules you defined; what is the system to do with the prefix "xx"? There is no matching rule. Please restate your rules and/or examples.

    kind regards,

    Jos

  8. #8
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    Quote Originally Posted by JosAH View Post
    There is no way the first system produces that output. That is a Semi Thue System and has to obey the rules you defined; what is the system to do with the prefix "xx"? There is no matching rule. Please restate your rules and/or examples.

    kind regards,

    Jos
    xxMxMxxxMxxx
    BAA?
    I die a little on the inside...
    Every time I get shot.

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Supamagier View Post
    xxMxMxxxMxxx
    BAA?
    No, you'd get xBMAMA

    kind regards,

    Jos

  10. #10
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    He said output, not replace.

    Anyway, varma, you've gotta show us what you've done so far or at least what you've tried. Really, nobody is gonna do your homework. We're here to help.
    I die a little on the inside...
    Every time I get shot.

  11. #11
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Supamagier View Post
    He said output, not replace.
    Sorry, my bad; using the String.indexOf( ... ) method will be enough then.

    kind regards,

    Jos

  12. #12
    AndreB's Avatar
    AndreB is offline Senior Member
    Join Date
    Dec 2009
    Location
    Stuttgart, Germany
    Posts
    114
    Rep Power
    0

    Default

    a simple final state machine would be enough i think. do your own simulat0r :-P
    (also it will be equal to regular expressions)
    "There is no foolproof thing; fools are too smart."
    "Why can't you solve my Problem ?"

Similar Threads

  1. HELP PLEASE! Need reply ASAP
    By SteroidalPsycho in forum New To Java
    Replies: 3
    Last Post: 10-21-2009, 09:28 AM
  2. Need answer asap!!!
    By uranis_khai in forum New To Java
    Replies: 3
    Last Post: 07-07-2009, 10:48 AM
  3. [SOLVED] Threads Help, I think? Please Help ASAP!
    By tornado in forum New To Java
    Replies: 1
    Last Post: 11-30-2008, 05:33 AM
  4. Need Java Help ASAP
    By L-dog in forum New To Java
    Replies: 22
    Last Post: 10-03-2008, 12:54 AM
  5. array problems need your help ASAP!
    By notherand in forum New To Java
    Replies: 1
    Last Post: 06-29-2008, 09:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •