天天看点

PAT 踩过的坑

这里想吐槽一下pat 的输出 格式问题。pat常见的输出格式是:

两个数字之间通常有空格,但是最后一个数字之后是没有空格的。这个一般很好实现。在<code>i!=n-1</code> 输出空格即可。如果<code>i==n-1</code>时,就只输出结果即可。

但是,今晚遇到了一个更加奇葩的题。题目是甲级1101,我在输出格式的地方卡了好久。我的输出代码是:

因为是二刷题目,我翻了翻之前写的答案,比对输出代码:

我在最后多了一个<code>printf("\n")</code>,我看了好久都一直觉得是多余【如果是对于正常的测试用例的话的确多余,但是对于某些特殊测试用例的话,就不一定多余了。】我们再看一下这题的输出要求:

for each test case, output in the first line the number of pivot candidates. then in the next line print these candidates in increasing order. there must be exactly 1 space between two adjacent numbers, and no extra space at the end of each line.

感觉题目的意思是:一定要输出第二行,即使第二行什么也没有 正是由于这个原因,才导致我的程序在<code>count=0</code>时就没有输出第二行,导致报格式错误。于是修改代码如下:

ac了!