• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Prompt algorithm

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Input file:

output file:
duplicate lines, indicating the number of repetitions
what algorithm?
 
lowercase baba
Posts: 13013
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
petr pavlovich
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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(
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How did you mentally come up with that output?
 
fred rosenberger
lowercase baba
Posts: 13013
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

((((((
Console
 
Marshal
Posts: 26908
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.>
 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you don't need to change anyTypeArray (below) as you scan
through it (add, delete, etc.), a further improved version is:
Jim ... ...
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic