problem 1000: A+B problem

又趁着興趣,把這個problem 1000看了看,發覺這道題純粹是爲了介紹acm代碼提交方面問題的example,但還是用C做了一下,題目在這裏(摸我),代碼如下:

#include <stdio.h>

int main()
{
    int a,b;
    scanf("%d %d",&a, &b);
    printf("%d\n",a+b);
    return 0;
}
沒想到的是提交之後,提示“Wrong Answer”,檢查了之後再提交,發現還是提示“Wrong Answer”,截圖如下,甚是氣惱:


於是,開始仔細的把題目看了幾遍,發現ustcpku的題目不同,zju給出了正確的答案:

#include <stdio.h>

int main()
{
    int a,b;
    while(scanf("%d %d",&a, &b) != EOF) //注意此處的循環輸入!
        printf("%d\n",a+b);
    return 0;
}


最後,提交,終於成功了!

這裏提醒了我要注意scanf函數的用法,scanf函數返回從鍵盤緩衝區讀取的字符數,如果在與其格式化輸入參數不匹配的時候會返回EOF(-1);

同樣的道理,當鍵盤緩衝區無數據時,scanf函數會阻塞,直到用戶從鍵盤中輸入,(回車符);

注意第二段代碼中的循環輸入!


PS:關於acm代碼提交,ustc沒找到說明,可以參考zju(點我)的說明,以下是摘錄的一些錯誤說明:

Q:What is the meaning of the judge's reply XXXXX?
A:Here is a list of the judge's replies and their meaning:

Queuing : The judge is so busy that it can't judge your submit at the moment, usualy you just need to wait a minute and your submit will be judged.

Accepted : OK! Your program is correct!.

Presentation Error : Your output format is not exactly the same as the judge's output, although your answer to the problem is correct. Check your output for spaces, blank lines,etc against the problem output specification.

Wrong Answer : Correct solution not reached for the inputs. The inputs and outputs that we use to test the programs are not public (it is recomendable to get accustomed to a true contest dynamic ;-).

Time Limit Exceeded : Your program tried to run during too much time.

Memory Limit Exceeded : Your program tried to use more memory than the judge default settings.

Output Limit Exceeded: Your program tried to write too much information. This usually occurs if it goes into a infinite loop. Currently the output limit is 1M bytes.

Non-zero Exit Code: Your program exited returning a non-zero value to the shell. For languages such as C, this probably means you forgot to add "return 0" at the end of the program. For interpreted languages NZEC will usually mean that your program either crashed or raised an uncaught exception.

Compile Error : The compiler (gcc, g++, fpc, etc) could not compile your program. Of course, warning messages are not error messages. Click the link at the judge reply to see the actual error message.

Out Of Contest Time: this message can only appear during a contest, if a program is submitted out of contest time.

No such problem: Either you have submitted a wrong problem id or the problem is unavailable.

Segmentation Fault : The possible cases of your encountering this error are:

  • 1.buffer overflow --- usually caused by a pointer reference out of range.
  • 2.stack overflow --- please keep in mind that the default stack size is 8192K.

Floating Point Error : Divide by 0

Runtime Error : See FAQ below

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章