本文介绍了如何针对输入测试用例文件测试我的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我参加了一些编码竞赛,幸运的是我的代码也运行了.然而,我的解决方案出乎意料,因为我对输入的模式有误.

I was participating in some coding contests and luckily my code also ran. However my solution was not expected because i was wrong with the pattern of taking input.

这个问题涉及将一个整数作为输入并执行一些操作并返回一个不同或相同的整数.我对程序没有任何问题,我只是不知道如何编码以便接受这样的输入

The question involved taking in an integer as an input and performing some operation and returning a different or same integer. I do not have any problem with the program, I just don't know how to code so as to take inputs like this

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

我的代码是


My code is

#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 中整数数组的大小?

How am i supposed to know how many inputs they will give ( although they do provide a maximum limit). And if i use an array to store these inputs whose size is equal to the maximum limit, how do i check the size of an integer array in c ?

我将感谢任何人提供一小段代码的帮助.此外,如果我能够针对输入测试文件对其进行测试并生成output.txt"(输出文件).我已经有了所需的输出文件des.txt".那么我如何匹配两个文件是否相同?

I will appreciate anybody helping out with a small piece of code. Also if am able to test it against an input test file and generate an "output.txt" (output file). I already have the desired output file "des.txt". Then how can i match whether both the files are same or not ?

推荐答案

#include <stdio.h>
int scanned;
while((scanned = scanf("%d", &number)) != EOF) {
    printf("%d\n", functionReturningInteger(number));
}

如果scanf在转换成功前检测到输入结束,则返回EOF.

If scanf detects the end of input before a successful conversion, it returns EOF.

对于其他问题,重定向输入和输出,

For the other questions, redirect input and output,

$ ./your_prog < input.txt > output.txt

比较

$ comp output.txt des.txt

这篇关于如何针对输入测试用例文件测试我的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:43