구현(Implementation)

백준 7785번 : 회사에 있는 사람

cepiloth 2018. 6. 15. 12:18
반응형

https://www.acmicpc.net/problem/7785


1. 문제 요약

상근이는 세계적인 소프트웨어 회사 기글에서 일한다. 이 회사의 가장 큰 특징은 자유로운 출퇴근 시간이다. 따라서, 직원들은 반드시 9시부터 6시까지 회사에 있지 않아도 된다. 각 직원은 자기가 원할 때 출근할 수 있고, 아무때나 퇴근할 수 있다. 상근이는 모든 사람의 출입카드 시스템의 로그를 가지고 있다. 이 로그는 어떤 사람이 회사에 들어왔는지, 나갔는지가 기록되어져 있다. 로그가 주어졌을 때, 현재 회사에 있는 모든 사람을 구하는 프로그램을 작성하시오.


2. 알고리즘

string map 을 선언하고 map 에 값이 enter 인 경우만 리버스 이터레이터로 출력 한다.


3. 코드

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
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>         // greater 사용 위해 필요  
#include <string>
#include <map>
#include <math.h>
#include <stack>
using namespace std;
 
int main() {
    std::ios::sync_with_stdio(false); cin.tie(0);
 
    int n; cin >> n;
 
    map<stringstring> m;
    while(n--) {
        string s; cin >> s;
        string ss; cin >> ss;
        m[s] = ss;
    }
 
    map<stringstring>::reverse_iterator iter;
    for(iter = m.rbegin(); iter != m.rend(); iter++) {
 
        if (iter->second == "enter") {
            cout << iter->first << "\n";
        }
    }
    return 0;
}
cs

반응형