scanf in 10013!

Write here if you have problems with your C source code

Moderator: Board moderators

Post Reply
Julien Cornebise
Experienced poster
Posts: 145
Joined: Sat Feb 23, 2002 2:00 am
Location: Paris, France
Contact:

Post by Julien Cornebise »

Hi (re) :)

the easiest way to read the input is to use the fact than
[c]scanf("%d", &n);[/c]
will read an integer, skipping whatever white space of newline present before, so you don't have to care about it.
So :
[c]
int entry[2][MAXN];
int nscenar;
int ndigits;
int i;
/* For each scenario */
for (scanf("%d", &nscenar); nscenar > 0; nscenar--) {
scanf("%d", &ndigits);
/* For each digit */
for (i=0; i<ncase; i++)
scanf("%d %d", &entry[0], &entry[1]);
/* And then, solve ;) */
/* ... */
}

[/c]
should do it.

Hope that helps :)
jakabjr
Learning poster
Posts: 56
Joined: Wed Mar 23, 2005 9:21 pm
Location: Timisoara, Romania

Post by jakabjr »

more generally, if u need to skip any number of blank spaces (which are specified by isspace() for instance), u can also use scanf(" ");
the "%s", "%d", "%f" type conversion specifiers do this implicitly.
Understanding a problem in a natural way will lead to a natural solution
Post Reply

Return to “C”