Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在像SPOJ这样的竞争性编程网站中,我如何处理输入/输出格式?_C++_C - Fatal编程技术网

C++ 在像SPOJ这样的竞争性编程网站中,我如何处理输入/输出格式?

C++ 在像SPOJ这样的竞争性编程网站中,我如何处理输入/输出格式?,c++,c,C++,C,大多数问题的解决方案格式为 1) 输入测试用例的数量 2) 给出输入的“测试用例”数量 3) 立即输出每个测试用例的答案 Example 3(Total test cases) 12 3( test case 1) 32 4( test case 2) 65 1(test case 3) output: 4(solution to test case1) 3(sol to tc2) 8(sol to tc3) 一旦我计算了每个测试用例的答案,我是否需要将其存储在某

大多数问题的解决方案格式为
1) 输入测试用例的数量
2) 给出输入的“测试用例”数量
3) 立即输出每个测试用例的答案

Example  
3(Total test cases)  
12 3( test case 1)  
32 4( test case 2)  
65 1(test case 3)  

output:  
4(solution to test case1)  
3(sol to tc2)
8(sol to tc3)
一旦我计算了每个测试用例的答案,我是否需要将其存储在某个地方,直到所有测试用例都结束,然后逐行显示答案


如果我的想法正确,我应该使用数组来存储每个测试用例的解决方案,然后在最后显示数组。另一种解决方案是,输入测试用例并打印解决方案。但这似乎并没有被在线法官所接受。如何在c/c++中处理这个问题。在python中,它应该很简单。

您不需要存储结果。在计算结果时立即打印结果。
stdin
stdout
是相互不干扰的独立流。
c
中SPOJ程序的一般结构如下:

int main(void) {
    ....
    int tc;
    scanf("%d", &tc); // Read number of testcases
    for(i=0; i<tc; i++)
    {
        readInput(&input...);
        computeResult(input...., &output....);
        printResult(output....);
    }
    return 0;
}
int main(无效){
....
int tc;
scanf(“%d”,&tc);//读取的测试用例数

对于(i=0;i您不需要存储结果。请立即打印它们。
stdin
stdout
是分开的streams@EugeneSh.您应该这样回答。@EugeneSh。不接受立即打印。输入所有测试用例后,答案必须是打印机。请阅读相应的在线判断网站指南,或k在他们提供的论坛上。大多数人都使用标准的输入输出文件描述符RST与您提供的程序进行通信,尽管我们在这里无法最终确定。@Abhishekkunsoor我不相信您,抱歉。我以前完成过一系列SPOJ挑战,这从来都不是问题。我只需要附加一个“\n”格式不清楚。我问这个问题太傻了!:/