我參與了一些編碼競賽,幸運的是我的代碼也運行了。然而,我的解決方案並沒有預料到,因爲我對輸入模式有誤。如何根據輸入測試用例文件測試我的程序
問題涉及取入的整數作爲輸入,並執行一些操作並返回一個不同或相同的整數。我沒有與任何程序問題,我只是不知道如何代碼,以便採取投入這樣
Input
The input will contain several test cases (not more than 10).
Each test case is a single line with a number n, 0 <= n <= 1 000 000 000.
It is the number given as input.
Output
For each test case output a single line, containing the integer returned.
Example
Input:
12
2
Output:
13
2
我的代碼是
#include <stdio.h>
int functionReturningInteger(int n)
{
// implementation
........
return num;
}
int main(void)
{
int number;
//printf("Enter the number: ");
scanf("%d",&number);
printf(functionReturningInteger(number));
return 0;
}
如何我應該知道,他們將有多少投入給(雖然他們確實提供了最大限制)。如果我使用數組來存儲這些大小等於最大限制的輸入,我該如何檢查c中整數數組的大小?
我會很感激任何人幫助一小段代碼。此外,如果我能夠對輸入測試文件進行測試並生成「output.txt」(輸出文件)。我已經有了所需的輸出文件「des.txt」。那我怎麼能匹配這兩個文件是否相同?
你有一個錯誤在你的代碼'的printf( 「%d \ n」,functionReturningInteger(數字) );' – aisbaa 2012-07-18 07:33:33
是的..其實我不得不定製代碼以避免發佈不必要的代碼。謝謝! – OneMoreError 2012-07-18 07:36:19
@gcc賦值「不超過10」,因此您可以在這種特殊情況下安全地使用固定大小的數組。 – 2012-07-18 07:46:52