Input Problem

Apr 15, 2013 at 12:39pm
How would I handle an input like this in C++:
The input begins with a single positive integer on a line by itself indicating the number of cases, each described as below. This is followed by a blank line, and there will be a blank line between each two consecutive inputs.

Eg:
2

harry
tom
pat
jill

jim
jack
betty
Apr 15, 2013 at 1:32pm
closed account (3qX21hU5)
Use a variable to hold the blank lines.

1
2
3
4
5
6
7
8
9
10
11
cin >> cases;
cin >> throwAway;    // Handles the blank line after the case input

for (int i = 0; i != cases; ++i)
{
    while (something for your case)
    {
        // Do whatever you need to for each case
    }
    cin >> throwAway; // Handles the space between each case
}



That is probably the most simple way to go about it I would guess. There is probably a better way like using the blank lines to determine when the next case is, but I can't be sure without the whole problem.
Last edited on Apr 15, 2013 at 1:34pm
Topic archived. No new replies allowed.