I participated in a coding competition today, and I found that almost all of the command line input our programs needed to receive would start with an integer representing the amount of data sets to follow. There were 6 different problems, and they all started this way.
For example, one sample problem had: "Input to this problem will begin with a line containing a single integer N (1 <= N <= 100) indicating the number of data sets. Each data set consists of the following components:
- A line containing a single integer W that specifies the number of wormholes
- A series of W lines containing....
- etc. "
Pretty much all the competition problems had this format, with the first integer representing the amount of data sets to follow.
My initial reaction (and the way I tried to solve the problem) was just using a vector of size N, where each element represented a data set. Trouble is, there are a whole bunch of things in these data sets. Using this approach often left me with a vector of vector of vectors (maybe an exaggeration but you get the idea) which was very hard to manage.
Another idea was looping through the entire program N times, but this doesn't always seem that applicable.
I realize this is a vague question, but that's because I'm looking for a general solution to this type of problem. What is the best approach to handling this type of input?