Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
helsonxiao opened this issue Mar 26, 2021 · 1 comment
Open

Comments

@helsonxiao
Copy link
Contributor

#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
@helsonxiao
Copy link
Contributor Author

这个改动容易造成历史 md5 不兼容,如果实现的话得是一个可配选项。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant