728x90
반응형
https://www.acmicpc.net/problem/19583
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
string t1, t2, t3, time, name;
int t, cnt = 0;
cin >> t1 >> t2 >> t3;
set<string> first;
int s = 60 * stoi(t1.substr(0, 2)) + stoi(t1.substr(3, 2));
int e = 60 * stoi(t2.substr(0, 2)) + stoi(t2.substr(3, 2));
int q = 60 * stoi(t3.substr(0, 2)) + stoi(t3.substr(3, 2));
while(cin >> time >> name){
t = 60 * stoi(time.substr(0, 2)) + stoi(time.substr(3, 2));
if(t <= s){
first.insert(name);
}
if(t >= e && t <= q){
if(first.find(name) != first.end()){
cnt++;
first.erase(name);
}
}
}
cout << cnt << endl;
return 0;
}
시간이 HH:MM 형식으로 주어지므로 시간은 substr(0, 2), 분은 substr(3, 2)이고 문자열이므로 stoi를 통해 문자로 변환해주어야 한다. 1시간 = 60분 이므로 60 * 시간 + 분으로 바꾸어 비교한다.
채팅 기록(시간, 이름)을 한 줄씩 입력받아
시간이 개강총회를 시작하기 전이면 first에 이름을 저장한다. 이 때 set stl은 중복을 허용하지 않기 때문에 이름이 중복되어 저장되지 않는다.
시간이 개강총회를 끝내고 나서, 스트리밍을 끝낼 때까지이면 first에 이름이 있는지 확인해서 있으면 cnt를 증가시키고 중복해서 세면 안되기 때문에 first에 있는 해당 이름을 삭제한다.
728x90
반응형
'Algorithm > BAEKJOON' 카테고리의 다른 글
[BOJ] 7656번 만능 오라클 (C++) (0) | 2022.02.05 |
---|---|
[BOJ] 4358번 생태학 (C++) (0) | 2022.02.04 |
[BOJ] 2941번 크로아티아 알파벳 (C++) (0) | 2022.02.03 |
[BOJ] 23028번 5학년은 다니기 싫어요 (C++) (0) | 2022.02.02 |
[BOJ] 20291번 파일 정리 (C++) (0) | 2022.02.02 |