1 / 8
Mar 2009

I normally use C#, but have started using C++ for some other sites.

How do I handle the input for:
spoj.pl/problems/PARKINGL/2

I can't figure out how to know when to make my program terminate.

  • created

    Mar '09
  • last reply

    Feb '11
  • 7

    replies

  • 150

    views

  • 4

    users

  • 1

    link

At the risk of stating the obvious... Each dataset ends with a blank line, and the number of datasets is the first line of input, so simply terminate after the processing the final dataset.

simes,
No worries smiley

How do I read the blank line? Using scanf and cin the app just sits waiting, it's not reading the blank line.

int getInt()
{
	char s[10];
	cin >> s;
	printf("-%d-\n",s[0]);
	return atoi(s);
}

I put the above sample together, it won't print anything for the blank line though. The other method was replacing the cin line with scanf("%s", &s);

Ah I see.

I've not used C or C++ for a long while now, but if you read the 1st character of the line using a %c, you'll either get a carriage return (windows) or a line feed (*nix). If you get something else, read the remainder of the line, put it all together and convert it to an integer.

But there's probably a better way!

1 year later

How can I terminate the input for each dataset?

6
19
17
13
1
99 -> end of part one
1
3
20
16 -> end of part two(?)

fixed that for you.

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 14 6d

Want to read more? Browse other topics in C and C++ or view latest topics.