| Author |
Prompt algorithm
|
petr pavlovich
Greenhorn
Joined: Jul 10, 2011
Posts: 22
|
|
Input file:
output file:
duplicate lines, indicating the number of repetitions
what algorithm?
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9940
|
|
clearly you know the algorithm...you generated the output in your post.
How did you figure out that this:
bbb -3
aaa - 2
goes in your output file?
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
petr pavlovich
Greenhorn
Joined: Jul 10, 2011
Posts: 22
|
|
fred rosenberger wrote:clearly you know the algorithm...you generated the output in your post.
How did you figure out that this:
bbb -3
aaa - 2
goes in your output file?
??? I have not understood You(
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
How did you mentally come up with that output?
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9940
|
|
In your original post, you gave us the input:
ddd
bbb
ccc
aaa
bbb
aaa
bbb
SOMEHOW, you were able to then say
"I want my program to output this:
bbb -3
aaa - 2
You used your own brain to figure out what that output should be. How did you do it in your head?
I am 100% serious in saying you should write down the steps you used in your head. make them simple and clear. When you've done that, go back and refine them to be more specific. You can't say "I counted the number of times bbb occurred", because I would come back with "How did you know to count 'bbb'? Once you knew you needed to count those, how did you count them?"
|
 |
petr pavlovich
Greenhorn
Joined: Jul 10, 2011
Posts: 22
|
|
((((((
Console
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16482
|
|
The standard Java idiom for iterating through the elements of an array is this:
Whereas you have this:
See the difference? You are iterating one time too many.>
|
 |
Jim Hoglund
Ranch Hand
Joined: Jan 09, 2008
Posts: 525
|
|
If you don't need to change anyTypeArray (below) as you scan
through it (add, delete, etc.), a further improved version is:
Jim ... ...
|
BEE MBA PMP SCJP-6
|
 |
 |
|
|
subject: Prompt algorithm
|
|
|