#P2. [Sleeping Cup #1] Have a check

[Sleeping Cup #1] Have a check

Person in Charge

Attention

Please strictly follow the submission instructions.

Problem Description

Given an answer file and an output file, perform a full-text comparison between them and return relevant information.

Submission Method

Use the following template. Complete the check function at (2) to make it return the required information based on the problem description. If needed (though the standard solution does not require it), you may define variables or functions at (1). Do not modify any other part of the template. After completing the code, submit it in C++.

In the check function:

  • answer: The answer file, containing only ASCII printable characters, half-width spaces, and line breaks (\n), with a length not exceeding 10610^6.
  • output: The output file, containing only ASCII printable characters, half-width spaces, and line breaks (\n), with a length not exceeding 10610^6.
  • The return value should follow one of these 66 templates based on the comparison result:
    • Accepted. (exact match)
    • Wrong Answer: Missing Line on Line %d.(missing line at the end of the output file)
    • Wrong Answer: Missing Character on Line %d, Column %d. (missing character at the end of a line)
    • Wrong Answer: Extra Line on Line %d. (extra line at the end of the output file)
    • Wrong Answer: Extra Character on Line %d, Column %d. (extra character at the end of a line)
    • Wrong Answer: Wrong Answer on Line %d, Column %d. (character mismatch)

Additionally, the provided sample files (.ans and .out) contain important information (e.g., when multiple mismatches are found, the first error should be reported). Please review them carefully before coding.

#include <bits/stdc++.h>
using namespace std;
// (1)
string check(string answer, string output)
{
    if (answer == output) return "Accepted.";
    // (2)
}
int main()
{
    freopen("check.in", "r", stdin);
    freopen("check.out", "w", stdout);
    string ansa, out;
    stringstream s0, s1, s2;
    bool sepa = false;
    char c = getchar();
    while (c != EOF)
    {
        s0 << (int) c << endl;
        if (c == 127) sepa = true;
        else if (sepa) s2 << '*';
        else s1 << '*';
        c = getchar();
    }
    s1 >> ansa;
    s2 >> out;
    int tmp = 0, cnt = 0;
    sepa = false;
    while (s0 >> tmp)
    {
        if (tmp == 127)
        {
            sepa = true;
            cnt = 0;
        }
        else
        {
            if (sepa) out[cnt] = tmp;
            else ansa[cnt] = tmp;
            cnt++;
        }
    }
    cout << check(ansa, out);
    return 0;
}

Samples

Download the sample files from the link below.

There are 1717 samples in total. The .in files are the actual input files, .ans files are the answer files, .out files are the output files, and .chk files are the expected results you should produce.

When testing locally, use the .in file as input and compare your output with the .chk file. The .ans and .out files can be deleted during testing.

Attachments

Download the files here.

Official Solution

link