Results 1 to 12 of 12
Thread: Need some help ASAP
- 01-05-2010, 11:53 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 1
- Rep Power
- 0
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.
-
- 01-06-2010, 10:28 PM #3
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. ;)
- 01-07-2010, 02:09 AM #4
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
You could also use patterns: Java Tutorials: Regex
Last edited by collin389; 01-07-2010 at 02:12 AM.
- 01-07-2010, 02:23 AM #5
Member
- Join Date
- Sep 2009
- Posts
- 30
- Rep Power
- 0
- 01-07-2010, 02:28 AM #6
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
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.
- 01-07-2010, 07:25 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
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
- 01-07-2010, 10:02 AM #8
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
- 01-07-2010, 11:14 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 01-07-2010, 06:54 PM #10
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
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.
- 01-07-2010, 06:59 PM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 01-08-2010, 12:15 AM #12
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
-
HELP PLEASE! Need reply ASAP
By SteroidalPsycho in forum New To JavaReplies: 3Last Post: 10-21-2009, 08:28 AM -
Need answer asap!!!
By uranis_khai in forum New To JavaReplies: 3Last Post: 07-07-2009, 09:48 AM -
[SOLVED] Threads Help, I think? Please Help ASAP!
By tornado in forum New To JavaReplies: 1Last Post: 11-30-2008, 04:33 AM -
Need Java Help ASAP
By L-dog in forum New To JavaReplies: 22Last Post: 10-02-2008, 11:54 PM -
array problems need your help ASAP!
By notherand in forum New To JavaReplies: 1Last Post: 06-29-2008, 08:59 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks