-
Notifications
You must be signed in to change notification settings - Fork 0
/
securedoors.cpp
69 lines (55 loc) · 1.57 KB
/
securedoors.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* @file securedoors.cpp
* @author William Weston
* @brief Secure Doors Problem From Kattis
* @version 0.1
* @date 2023-07-04
*
* @copyright Copyright (c) 2023
*
* Source: https://open.kattis.com/problems/securedoors
*/
#include <cstdlib>
#include <iostream>
#include <string>
#include <unordered_set>
constexpr auto anomaly = " (ANOMALY)";
auto main() -> int
{
for ( int N; std::cin >> N; )
{
auto in_building = std::unordered_set<std::string>();
for ( auto log_entry = 0; log_entry < N; ++log_entry )
{
auto event = std::string();
auto employee = std::string();
std::cin >> event >> employee;
if ( event == "entry" )
{
// output event
std::cout << employee << " entered";
// check for anomaly ( employee already in building )
if ( auto result = in_building.find( employee ); result != in_building.end() )
{
std::cout << anomaly;
}
std::cout << '\n';
// add employee
in_building.insert( employee );
}
else if ( event == "exit" )
{
// output event
std::cout << employee << " exited";
// check for anomaly ( employee NOT in building )
if ( auto result = in_building.find( employee ); result == in_building.end() )
{
std::cout << anomaly;
}
std::cout << '\n';
in_building.erase( employee );
}
}
}
return EXIT_SUCCESS;
}