ZeroJudge A221: Big Number of Teams Will Solve This

UVa 11734 – Big Number of Teams will Solve This

Writing code for a simple programming problem isn't too big of an issue, but inexperienced newcomers might not realize that their output needs to match the Judge's output exactly.

Usually, they might output extra spaces because they think it makes the output look nicer.

But the reality is every character you output should match exactly with the Judge's output.

If you output extra spaces when submitting to the Judge, you will receive an "Output Format Error."

If the output is still incorrect after the Judge ignores spaces, you will receive a "Wrong Answer" verdict.

And a verdict of "Yes" is obtained when the output matches exactly.

In this problem, you need to evaluate the submitter's output and provide the Judge's verdict.

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
The first line will contain a positive integer T (T < 20), indicating the number of data sets.
Each dataset will consist of two lines.
The first line is the team's output.
The second line is the Judge's output.

Each line will contain at least one character and at most 20 characters.
The team's output consists of spaces and characters, while the Judge's output only consists of characters.
For each dataset, you need to output one line. Each line contains the judgment number and the judgment result. Please refer to the sample test.
3
yes
yes
Casematters
casematters
no space please
nospaceplease
Case 1: Yes
Case 2: Wrong Answer
Case 3: Output Format Error
ZeroJudge A221 範例測資

Thought Process

You can use getline to read strings. After reading T, remember to call cin.ignore(). After reading the data, if the two strings are the same, you can directly output "Yes". If they are different, then you need to do the following comparison.

Use a map to record the occurrence count of each non-space character. While iterating through the team's output, increment Map[char] for each character encountered. While iterating through the Judge's output, decrement Map[char] for each character encountered.

Iterate through the map using a for loop (auto it: Map), and initialize a boolean variable WA to False. If at any point during the loop it.second != 0, it means there are extra or missing characters, so set WA to True and break out of the loop.

If WA == True, output "Wrong Answer". If WA is still False after the loop ends, it means there were only extra spaces, so output "Output Format Error".

Sample Code-ZeroJudge A221: Big Number of Teams Will Solve This

#include <iostream>
#include <map>
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    cin.ignore();
    for (int i = 0; i<N; i++)
    {
        string a, b;
        getline(cin, a);
        getline(cin, b);
        cout << "Case " << i+1 << ": ";
        if (a == b) cout << "Yes\n";
        else
        {
            map<char, int>MAP;
            for (int j = 0; j<a.length(); j++)
            {
                if (a[j] != ' ') MAP[a[j]]++;
            }
            for (int j = 0; j<b.length(); j++)
            {
                if (b[j] != ' ') MAP[b[j]]--;
            }
            bool WA = false;
            for (auto it:MAP)
            {
                if (it.second != 0)
                {
                    WA = true;
                    break;
                }
            }
            if (WA) cout << "Wrong Answer\n";
            else cout << "Output Format Error\n";
        }
    }
}

//ZeroJudge A221
//Dr. SeanXD

Comments