Simple user registry code in C++ I'm learning C++, and would like more experienced folks to review my code, and point out what could be improved/changed.
Here's the problem that should be solved (taken from Kattis Securedoors)

You need to write a simple software auditor for tracking employees
entering and exiting your building using their access cards (each card
uniquely identifies the employee holding the card). Your software
needs to look at the access log and determine if there are any
anomalies. There are two types of anomalies your software should
detect:

a user entering the building when, according to the log, they are
already supposed to be in the building
a user exiting the building
when, according to the log, they are not supposed to be in the
building

When your software sees someone enter a building (even if
it’s an anomaly), that person is assumed to be inside the building
from that point on, until he exits. Similarly, if your software sees
someone exit the building (even if it’s an anomaly), that person is
assumed to not be in the building from that point on, until he enters
again. At the beginning of the log, everyone is assumed to be outside
the building.
Input
Input Input starts with a number 1≤n≤10001≤n≤1000 indicating the
length of the log. This is followed by nn lines, each line describing
either an entry or exit by an employee. Each description is of the
form ‘entry name’ or ‘exit name’, where name is a string of up to 20
uppercase and/or lowercase characters (a-z).
Output
For each person’s entry or exit, print the name of the person,
followed by entered or exited. If the action is anomalous, print
(ANOMALY) afterward.
Sample Input 1
8
entry Abbey
entry Abbey
exit Abbey
entry Tyrone
exit Mason
entry Demetra
exit Latonya
entry Idella

Sample Output 1
Abbey entered
Abbey entered (ANOMALY)
Abbey exited
Tyrone entered
Mason exited (ANOMALY)
Demetra entered
Latonya exited (ANOMALY)
Idella entered


Here's my code (working sample)
#include &lt;iostream&gt;
#include &lt;unordered_map&gt;
#include &lt;string&gt;

class UserRegistry {
public:
  void UserEntered(const std::string&amp; user) {
    RegisterUserAction(user, &quot;entered&quot;);
  }

  void UserExited(const std::string&amp; user) {
    RegisterUserAction(user, &quot;exited&quot;);
  }

private:
  void LogAction(const std::string&amp; user, const std::string&amp; action, bool is_anomaly = false) {
    std::cout &lt;&lt; user &lt;&lt; &quot; &quot; &lt;&lt; action &lt;&lt; (is_anomaly ? &quot; (ANOMALY)&quot; : &quot;&quot;) &lt;&lt; std::endl;
  }

  void RegisterUserAction(const std::string&amp; user, const std::string&amp; action) {
    bool anomaly = false;
    if (action == &quot;entered&quot; &amp;&amp; registry[user] % 2 == 1) {
      anomaly = true;
    }

    if (action == &quot;exited&quot; &amp;&amp; registry[user] % 2 == 0) {
      anomaly = true;
    }

    if (!anomaly)
      registry[user]++;

    LogAction(user, action, anomaly);
  }

private:
  std::unordered_map&lt;std::string, int&gt; registry;
};

int main() {
  UserRegistry registry;
  int log_length;
  std::cin &gt;&gt; log_length;
  for (int i = 0; i &lt; log_length; ++i) {
    std::string user, action;
    std::cin &gt;&gt; action &gt;&gt; user;

    if (action == &quot;entry&quot;)
      registry.UserEntered(user);
    else if (action == &quot;exit&quot;)
      registry.UserExited(user);
  }

  return 0;
}
std::unordered_map&lt;std::string, int&gt; is an overkill. Since you only need to track of a presence - which is naturally boolean - std::set&lt;std::string&gt; is enough. As a perk benefit, notice that std::set::insert indicates whether the insertion was successful or not (this is an anomaly), and std::set::erase return a number of elements erased (0 means the key was not there, another anomaly):

    std::set&lt;std::string&gt; registry;
    bool UserEntered(const std::string&amp; user) {
        return !registry.insert().second;
    }
    bool userExited(const std::string&amp; user) {
        return registry.erase(user) == 0;
    }


Now both methods return the anomaly:

    bool anomaly;
    if (action == "entered") {
        anomaly = userEntered(user);
    } else if(action == "exited") {
        anomaly = userExited(user);
    } else {
        // handle error here
        return;
    }
    LogAction(....);