Hi! I'm currently in a competition, and I'm practicing by doing some tasks from last year. I found out that they test most programs by giving an input in one single line like this:
"5 3 23"
and that we need to get the three ints 5, 3 and 23 out of it (we get to know how many ints we need, but not the length). Is there an easy way to do this, or do I have to go through the whole string/char array looking for spaces?
If you input a character or int array as a string using cin, then the delimiter is the first white space it encounters. So, even if you have multiple cin statements, you can input on one line, separating each by a space.
The program will be tested by a machine. The machine first gives a value that says how many values it will give next time. Then it gives the all those values in a single line, with space between each value. If I had typed:
1 2 3
cin >> x;
cout << x;
for the second time it gives a value, and it gives the values 5, 2 and 17, it would come out as "5 2 17".
I want to know if I easily can get those values in an int array.
It cannot give them on multiple lines.
The reason cin >> x >> x >> x won't work, is because then I would need to know how many values it will give, while I'm programming it.