我参与了一些编码竞赛,幸运的是我的代码也运行了。然而,我的解决方案并没有预料到,因为我对输入模式有误。如何根据输入测试用例文件测试我的程序
问题涉及取入的整数作为输入,并执行一些操作并返回一个不同或相同的整数。我没有与任何程序问题,我只是不知道如何代码,以便采取投入这样
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