ZeroJudge K373: 0 and 1??@@@!!!

Xiaoming wants to create a program to output the questions he got wrong.

1 represents that he got right, and 0 represents that he got wrong.).

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
EOF inputs.
The first string is the name of the question.
The second item is 0 / 1 (whether it is completed or not).
Output the names of the questions where the second item is 0. Output in the order of input, and only output each question once if it appears multiple times.
a001 1
a002 1
a003 0
a003
b002 0
b003 0
b009 1
b002
b003
b002 0
b003 0
b002 0
b004 1
b004 1
b003 0
b002
b003

Thought Process

Because question names will repeat, but each should only be output once, you can use a Map/Set to check if the question (string) has already appeared. If the Map's Value is 0 (default is 0), it means it hasn't appeared yet, so you can output it, and then remember to increment the Map's Value by 1.

Sample Code-ZeroJudge K373: 0 and 1??@@@!!!

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

int main() {
    string str;
    int N;
    map<string, int>MAP;
    while (cin >> str >> N)
    {
        if (N == 0 && MAP[str] == 0) cout << str << "\n";
        MAP[str]++;
    }
}

//ZeroJudge K373
//Dr. SeanXD

Comments