반응형
https://www.acmicpc.net/problem/19583
19583번: 싸이버개강총회
첫번째 줄에는 개강총회를 시작한 시간 S, 개강총회를 끝낸 시간 E, 개강총회 스트리밍을 끝낸 시간 Q가 주어진다. (00:00 ≤ S < E < Q ≤ 23:59) 각 시간은 HH:MM의 형식으로 주어진다. 두번째 줄부터는
www.acmicpc.net
굳이 int로 바꿀 필요 없었다.
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
using namespace std;
int timeToInt(string& input) {
int res = 0;
res += (input[0] - '0') * 600;
res += (input[1] - '0') * 60;
res += (input[3] - '0') * 10;
res += (input[4] - '0');
return res;
}
int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0);
string input;
vector<int> v(3, 0); // [1] 시작 [2] 끝 [3] 방송끝
int res = 0;
for (int i = 0; i < 3; i++) {
cin >> input;
v[i] = timeToInt(input);
}
unordered_set<string> s;
string time, nickname;
while (getline(cin, time, ' ') && getline(cin, nickname)) {
// cout << time << ' ' << nickname << endl;
if (timeToInt(time) <= v[0]) { // 시작 전이면
s.insert(nickname);
} else if (timeToInt(time) >= v[1] && timeToInt(time) <= v[2]) {
if (s.find(nickname) != s.end()) {
s.erase(nickname);
res++;
}
}
// cout << res;
}
cout << res;
}
반응형
'<algorithm> > 백준' 카테고리의 다른 글
백준 1013 Contact c++ (1) | 2023.11.28 |
---|---|
백준 12891 DNA 비밀번호 c++ (0) | 2023.11.28 |
백준 9009 피보나치 c++ (0) | 2023.11.22 |
백준 10844 쉬운 계단 수 c++ (0) | 2023.11.20 |
백준 3184 양 c++ (0) | 2023.11.05 |