codeforces and EOF

Revision en1, by I_love_to_eat, 2017-12-11 14:45:46

I was trying to solve 320A - Magic Numbers and encountered a funny thing about codeforces. While this code ran okay

char c = getchar();
while (c != '\n')
{
...
}

my solution was giving me WA1, while running fine on my computer

int main()
{
	char c = getchar();
	while (c != EOF)
	{
		if (c != '1')
		{
			cout << "NO";
			return 0;
		}

		while (c == '1')
			c = getchar();

		if (c == '4')
		{
			c = getchar();

			if (c == '1') {
				continue;
			} else if (c == '4'){
				c = getchar();
				continue;
			} else if (c == EOF) {
				break;
			} else {
				cout << "NO";
				return 0;
			}
		} else if (c == EOF) {
			break;
		} else {
			cout << "NO";
			return 0;
		}
	}

	cout << "YES";

	return 0;
}

Maybe, it's the newline char at the end of the output? No 33100199.

So I numbered the NO'es to understand which one is malfunctioning: 33100283. And it was the second one. EOF looked suspicious, as I somehow remembered it could result in undefined behaviour, so hoped, that codeforces tests end with a new line character and it passed 33100350.

But still, my guess about EOF was a true speculation, googling didn't give me anything sensible, so can anybody explain what was the problem?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
ru3 Russian I_love_to_eat 2017-12-12 09:59:01 17 исправила опечатки
ru2 Russian I_love_to_eat 2017-12-11 14:51:52 1040
en1 English I_love_to_eat 2017-12-11 14:45:46 1343 Initial revision for English translation
ru1 Russian I_love_to_eat 2017-12-11 14:44:54 1343 Первая редакция (опубликовано)