회사에 있는 사람
공백을 구분된 두 입력을 받을 때 cin>>n>>m; 이어서 쓰면된다.
it은 interator로 it->first는 요소의 첫번째인 key를 의미하고 it->second은 요소의 value를 의미한다.
맵에 저장된 순서의 역순으로 출력하기 위해 rbegin()과 rend()를 사용하여 역순 순서로 출력할 수 있도록 해주었다.
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
map<string, string>employee;
int num = 0;
string name, work;
cin >> num;
for (int i = 0;i < num;i++) {
cin >> name>> work;
if (employee.find(name) != employee.end()) {
employee.erase(name);
}
employee.insert({ name,work });
}
for (auto it =employee.rbegin();it!=employee.rend();++it) {
if (it->second == "enter") {
cout << it->first << "\n";
}
}
return 0;
}