PAT
踩过的坑
1.输出格式的问题
这里想吐槽一下pat 的 输出 格式问题 。pat常见的输出格式是:
-
两个数字之间通常有空格,但是最后一个数字之后是没有空格的。这个一般很好实现。在
i!=n-1输出空格即可。如果i==n-1时,就只输出结果即可。
但是,今晚遇到了一个更加奇葩的题。题目是甲级1101,我在输出格式的地方卡了好久。我的输出代码是:
if(count ==0) cout << count;else cout << count <<"\n";for(i =0;i< count;i++){
cout << res[i];if(i != count -1) cout <<" ";}因为是二刷题目,我翻了翻之前写的答案,比对输出代码:
printf("%d\n",total);for(i =0;i<total;i++){printf("%d",record[i]);if(i!=total-1){printf(" ");}}printf("\n");
我在最后多了一个
printf("\n")
,我看了好久都一直觉得是多余【如果是对于正常的测试用例的话的确多余,但是对于某些特殊测试用例的话,就不一定多余了。】我们再看一下这题的输出要求:
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.
感觉题目的意思是:
一定要输出第二行,即使第二行什么也没有
正是由于这个原因,才导致我的程序在
count=0
时就没有输出第二行,导致报
格式错误
。于是修改代码如下:
cout << count <<"\n";if(count ==0) cout <<"\n";for(i =0;i< count;i++){
cout << res[i];if(i != count -1) cout <<" ";}AC了!


发布评论