John Matthews wrote:Hi Fudgie - you've posted in the C/C++ forum, so presumably you are going to be writing your code in one of those; can you confirm which one? The intersection of corresponding lists approach will require a bit more effort in C
fred rosenberger wrote:You don't necessarily need to convert them into integers...After all you may someday want to parse a file with input like:
etc. in other words, the fact that they look like integers now may not matter. What you are really looking for is repeated 2-character patterns. If you know they will always an only ever be 2-digit integers, then you can maybe take a few shortcuts. You'd know they can only be 0-99. That suggests you might be able to use an array with 100 elements to hold your count of each value found.
Now....Why 49? is it because it's the first element in the first row, or is there some other criteria? I don't think it's because it appears the most often, because I see 40 in there three times.
Piet Souris wrote:My idea is to build a Map<Integer, List<LineNumbers>> from the input. To determine how many times two integers appear as pair, you simply take the intersection of the two corresponding lists. Don't know about C++, but in java there's a handy method for that.
Piet Souris wrote:And welcome to the Ranch. Enjoy the stay!
Fudgie Braun wrote:By the way, is pseudo-code the same as algorithm?
fred rosenberger wrote:Parsing simply means reading in the data, and figuring out what parts are what. Any modern language will have built-in tools to help you do this.
One way you could try would be to read in the file a line at a time and save it to a string. Then you can use various String methods to break apart that string into the pieces. In your case, you're going to break it apart by the dashes (and discarding them). You'd be left with an array of six elements.
You could convert each to an integer type, or just continue using them as strings.
Pseudo‑code is independent of implementation language.
Fudgie Braun wrote:. . . Java pseudo-code . . . help in making a C++ source code version?
Fudgie Braun wrote:So you're saying I need to put the input text file into an array?
But before I put that into an array, I need to change each line into a string then put all those into the array?