Haoyu loves frogs very much, so he has raised many frogs and is a professional frog breeder. Haoyu wants to name his frogs, but he has so many frogs that he is afraid of forgetting and using duplicate names. So he wants you to help him write a program to determine whether a name has been used.
Haoyu prefers large frogs, so all the frogs he raises are quite big. Also, he prefers that the names of the frogs be in uppercase English letters, so they should only be named with uppercase English letters.
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
EOF inputs: each test case consists of multiple lines of input; each line contains a string composed of uppercase letters, which are the names Haoyu has thought of for the frogs. | For each line of input, output 1 if the name has appeared previously; otherwise, output 0. |
CHUANG HAOYU LIKE A FROG A FROG LIKE HAOYU CHUANG | 0 0 0 0 0 1 1 1 1 1 |
Thought Process
Since time is tight for this problem, using an unordered_map for checking would save time. Also, optimizing the input with cin would help improve timing.
Sample Code-ZeroJudge F259: Frog Names
#include <iostream>
#include <unordered_map>
#include <string>
using namespace std;
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
string str;
unordered_map<string, bool>MAP;
while (cin >> str)
{
cout << (MAP[str]++ ? "1\n" : "0\n");
}
}
//Z.O.J. F259
//Dr. SeanXD