Skip to content

是否应该帮用户 rstrip 掉输出中间行末尾的空格? #46

@helsonxiao

Description

@helsonxiao
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int singer1[6] = {8, 4, 6, 7, 5, 6};
    int singer2[6] = {5, 6, 3, 6, 4, 2};
    int singer3[6] = {3, 2, 4, 2, 3, 5};
    int num;
    scanf("%d", &num);
    printf(
        "%d %d %d   \n%d",
        singer1[num - 1], singer2[num - 1], singer3[num - 1],
        singer1[num - 1] + singer2[num - 1] + singer3[num -1]
    );
    return 0;
}

输出样例 1

8 5 3
16

用户输出

8 5 3   
16

这是一个测试用的程序,注意 "%d %d %d \n%d" 中,\n 之前的空格会导致答案错误。因为 Judger 在比较「用户输出」和「标准输出」时,只抹掉了用户输出最后一行的空格和换行符,输出中间行末尾的空格没有处理。

我把输出比较函数改成了如下

    def _compare_output(self, test_case_file_id, user_output_file):
        with open(user_output_file, "rb") as f:
            # 目前在上传测试用例时只去掉了最后一行的空格以及换行符,中间行末的空格没有去除,有待优化,但我们可以先帮用户 rstrip 掉
            output_lines = f.readlines()
            stripped_output_lines = [line.rstrip() for line in output_lines]
            content = b'\n'.join(stripped_output_lines)
        output_md5 = hashlib.md5(content.rstrip()).hexdigest()
        result = output_md5 == self._get_test_case_file_info(test_case_file_id)["stripped_output_md5"]
        return output_md5, result

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions