特殊的输入结束方式:EOF / A special signal to end the input EOF (end of file)
In some cases, there will not be an explicit signal for the end of input. In this situation, we check whether the end of a file is reached. There is a special signal EOF for the end of file, you can use it like this:
while (scanf("%d%d", &a, &b)!=EOF)
{
...
}
Or alternatively:
while (1)
{
if (scanf("%d%d", &a, &b)==EOF) break;
}
In local computer, this signal can be done by pressing F6 or Ctrl+z. Now, let us implement the negation problem again, but you are suppose to process until EOF.
-END OF ENGLISH VERSION-
=======================================================================================
有些时候,题目会说以eof表示文件的结束,所以这里给大家介绍一下EOF:
EOF的意思是end of file,表示输入的结束。
scanf函数的返回值如果为EOF的话,就表示输入结束了。比如题目要求你求两个数的和,以EOF结束,你就应该这样写:
while (scanf("%d%d", &a, &b)!=EOF)
{
...
}
或者这样:
while (1)
{
if (scanf("%d%d", &a, &b)==EOF) break;
}
在本机调试程序时,可以通过按 F6 或者 ctrl+z 来输入EOF
请完成下面这个题目(注意,此题和指导题2、3并不完全一样):
读入一个整数,并把这个数的相反数输出。
输入数据有多行,每行有一个整数。以EOF表示输入结束。
There are multiple lines of inut. Each contains an integer. Process until EOF.
输出数据同样有多行,每行对应输出相应整数的相反数。
Multiple lines for output. Each line contains a single negated number.
1 2 -3
-1 -2 3