728x90
320x100
7785번: 회사에 있는 사람
첫째 줄에 로그에 기록된 출입 기록의 수 n이 주어진다. (2 ≤ n ≤ 106) 다음 n개의 줄에는 출입 기록이 순서대로 주어지며, 각 사람의 이름이 주어지고 "enter"나 "leave"가 주어진다. "enter"인 경우는
www.acmicpc.net
반응형
📌 접근 방법
- map을 활용해서 출입 기록을 담는다
- set에 이름을 담고 사전 역순으로 정렬시켜둔다
- 정렬된 이름으로 map에서 찾아서 회사에 남아있으면 출력한다
✅ Pass Code
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
map< string, bool>m;
set<string, greater<string>> s;
for(int i=0; i<n; i++){
string x, y;
cin>>x>>y;
if(y=="enter")m[x]=true;
else if(y=="leave")m[x]=false;
s.insert(x);
}
for(auto it=s.begin(); it!=s.end(); it++){
string tmp = *it;
if(m[tmp])cout<<tmp<<'\n';
}
return 0;
}
![](https://t1.daumcdn.net/keditor/emoticon/friends1/large/028.gif)
728x90
반응형
'Coding Test > Baekjoon' 카테고리의 다른 글
[BOJ/백준/C++] 2485번 가로수 (0) | 2024.01.27 |
---|---|
[BOJ/백준/C++] 1934번 최소공배수 (0) | 2024.01.27 |
[BOJ/백준/C++] 11478번 서로 다른 부분 문자열의 개수 (0) | 2024.01.27 |
[BOJ/백준/C++] 18870번 좌표 압축 (0) | 2024.01.27 |
[BOJ/백준/C++] 1269번 대칭 차집합 (0) | 2024.01.27 |