How to use cin with a variable number of inputs?
I was in a programming competition yesterday and we had to read in input
of the form
n
a1 a2 ... an
m
b1 b2 ... bm
...
where the first line says how many inputs there are, and the next line
contains that many inputs (and all inputs are integers).
I know if each line has the same number of inputs (say 3), we can write
something like
while (true) {
cin >> a1 >> a2 >> a3;
}
But how do you do it when each line can have a different number of inputs?
No comments:
Post a Comment