天天看點

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了!