문제 링크입니다: https://www.acmicpc.net/problem/7785
7785번: 회사에 있는 사람
문제 상근이는 세계적인 소프트웨어 회사 기글에서 일한다. 이 회사의 가장 큰 특징은 자유로운 출퇴근 시간이다. 따라서, 직원들은 반드시 9시부터 6시까지 회사에 있지 않아도 된다. 각 직원은 자기가 원할 때 출근할 수 있고, 아무때나 퇴근할 수 있다. 상근이는 모든 사람의 출입카드 시스템의 로그를 가지고 있다. 이 로그는 어떤 사람이 회사에 들어왔는지, 나갔는지가 기록되어져 있다. 로그가 주어졌을 때, 현재 회사에 있는 모든 사람을 구하는 프로그램을 작성
www.acmicpc.net
map을 사용하면 쉽게 풀 수 있는 문제였습니다.
동일한 사람이 여러번 출근 퇴근할 수 있다는 점을 유의하면 되는 문제였습니다.
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 <iostream> | |
#include <map> | |
#include <string> | |
#include <vector> | |
#include <algorithm> | |
#include <functional> | |
using namespace std; | |
map<string, bool> visited; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N; | |
cin >> N; | |
vector<string> v; | |
for (int i = 0; i < N; i++) | |
{ | |
string s, s2; | |
cin >> s >> s2; | |
if (visited.count(s)) | |
{ | |
if (s2 == "enter") | |
{ | |
visited[s] = true; | |
} | |
else | |
{ | |
visited[s] = false; | |
} | |
continue; | |
} | |
v.push_back(s); | |
visited[s] = true; | |
} | |
sort(v.begin(), v.end(), greater<string>()); | |
int result = 0; | |
for (int i = 0; i < v.size(); i++) | |
{ | |
if (visited[v[i]] == true) | |
{ | |
cout << v[i] << "\n"; | |
} | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 1253번 좋다 (2) | 2019.10.21 |
---|---|
백준 2467번 용액 (0) | 2019.10.21 |
백준 6087번 레이저 통신 (0) | 2019.10.13 |
백준 1981번 배열에서 이동 (2) | 2019.10.08 |
백준 2957번 이진 탐색 트리 (0) | 2019.10.08 |