백준 7785번 회사에 있는 사람
< 백준 7785번 회사에 있는 사람 - 마포 코딩박 >
사용한 알고리즘: Set
문제에서 각 사람들의 출입기록을 주어집니다. 회사에 남아있는 사람을 출력하는 문제였습니다.
문제풀이는 다음과 같습니다.
(1) (코드 5)
사람들을 저장할 set을 만들어 줍니다.
(2) (코드 10~21)
enter 이 입력되면 set에 해당 사람을 insert, leave 가 입력되면 set에 해당 사람을 erase 합니다.
입력이 끝나고 set에 저장된 사람을 iterator을 사용해 출력해줍니다.
사용한 알고리즘: Set
문제에서 각 사람들의 출입기록을 주어집니다. 회사에 남아있는 사람을 출력하는 문제였습니다.
문제풀이는 다음과 같습니다.
(1) (코드 5)
사람들을 저장할 set을 만들어 줍니다.
(2) (코드 10~21)
enter 이 입력되면 set에 해당 사람을 insert, leave 가 입력되면 set에 해당 사람을 erase 합니다.
입력이 끝나고 set에 저장된 사람을 iterator을 사용해 출력해줍니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int N; | |
set<string> Employee; | |
int main(){ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); | |
cin >> N; | |
for (int i = 0; i < N; ++i){ | |
string a, b; | |
cin >> a >> b; | |
if(b == "enter") Employee.insert(a); | |
else Employee.erase(a); | |
} | |
auto iter = Employee.end(); | |
while(1){ | |
iter--; | |
cout << *iter << '\n'; | |
if(iter==Employee.begin()) break; | |
} | |
return 0; | |
} |
댓글
댓글 쓰기
긴 글 읽어주셔서 감사합니다.
궁금한게 있으시다면 댓글 달아주세요!