I did it this way:
unsigned char bases[11];
for (casenr = 1; casenr <= cases; casenr++) {
unsigned nrbases = 0;
char line[80];
fgets(line, sizeof(line), stdin);
nrbases = sscanf(line, "%hhu%hhu%hhu%hhu%hhu%hhu%hhu%hhu%hhu%hhu",
&bases[0], &bases[1], &bases[2], &bases[3], &bases[4],
&bases[5], &bases[6], &bases[7], &bases[8], &bases[9]);
...
sscanf returns the number of items matched, and it will stop at the
end of the line because you're only feeding it one line. (You can't
use fscanf for this because fscanf will skip over newlines.)
This approach only works if you know the maximum number of items and
the maximum line length ahead of time, but the code jam problems usually
specify exact limits for those.
--
Richard Braakman
--
You received this message because you are subscribed to the Google Groups
"google-codejam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-code?hl=en.