Hi all
I am new to the competition contests. I have some question that I hope that I can get some advice.
If a question never mention the number of lines that are expected to read from stdin. I will use a while loop to getline from stdin. The question is
1. Under what condition will I need to check so that I can terminate out of the loop since the the expected number of lines or condition might not be stated in the question.
Hope my question is clear. Please forgive me if this is begin discussed before cos I am totally new in contests.
Some question will be straight forward as they might tell you that the first line of the input will determine the number of line to be expected. eg
3 --> This number determine the number of lines that will be expected.
This is line number 1
This is line number 2
This is line number 3
Regards
Alan Chua
Reading in from Stdin in C++
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: Reading in from Stdin in C++
There is no standard input format for all problems. Sometimes you can read input an integer or double or string at a time, other problems require you to read line by line.
Check input and AC output for thousands of problems on uDebug!
-
- Experienced poster
- Posts: 122
- Joined: Tue Apr 16, 2002 10:07 am
Re: Reading in from Stdin in C++
If we are dealing with strings, I use:
If we are dealing with integers, I use:
Code: Select all
string s;
while(getline(cin, s))
{
}
Code: Select all
int n;
while (cin >> n)
{
}