[백준/BOJ] 백준 21774번 : 가희와 로그 파일
2022. 2. 2. 23:05ㆍ알고리즘 문제풀이
https://www.acmicpc.net/problem/21774
21774번: 가희와 로그 파일
2000년부터 2020년까지 연도 중에, 윤년인 것은 2000, 2004, 2008, 2012, 2016, 2020년 입니다.
www.acmicpc.net
각 레벨 이하의 로그가 발생한 시간들을 저장한 뒤, 각각 정렬하여 lower_bound와, upper_bound를 이용해서 문제를 해결했다
코드
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;
int n, q;
vector<string> log_info[7];
vector<string>::iterator it1;
vector<string>::iterator it2;
int main()
{
cin.tie(NULL);
ios_base::sync_with_stdio(false);
cin >> n >> q;
cin.ignore();
for (int i = 0; i < n; i++)
{
string input;
getline(cin, input);
stringstream ss(input);
string temp;
vector<string> maked;
while (getline(ss, temp, '#'))
{
maked.push_back(temp);
}
string this_log = maked[0];
int this_lv = stoi(maked[1]);
//this_lv이하의 레벨에 모두 넣는다
for (int i = 1; i <= this_lv; i++)
log_info[i].push_back(this_log);
}
//레벨별로 로그를 시간순으로 정렬
for (int i = 1; i <= 6; i++)
sort(log_info[i].begin(), log_info[i].end());
for (int i = 0; i < q; i++)
{
string input;
getline(cin, input);
stringstream ss(input);
string temp;
vector<string> maked;
while (getline(ss, temp, '#'))
{
maked.push_back(temp);
}
string this_start = maked[0];
string this_end = maked[1];
int this_lv = stoi(maked[2]);
it1 = lower_bound(log_info[this_lv].begin(), log_info[this_lv].end(), this_start);
it2 = upper_bound(log_info[this_lv].begin(), log_info[this_lv].end(), this_end);
cout << it2 - it1 << "\n";
}
return 0;
}
'알고리즘 문제풀이' 카테고리의 다른 글
[백준/BOJ] 백준 21775번 : 가희와 자원 놀이 (0) | 2022.02.02 |
---|---|
[백준/BOJ] 백준 21773번 : 가희와 프로세스 1 (0) | 2022.02.02 |
[백준/BOJ] 백준 21772번 : 가희의 고구마 먹방 (0) | 2022.02.02 |
[백준/BOJ] 백준 22236번 : 가희와 비행기 (0) | 2022.02.02 |
[백준/BOJ] 백준 22235번 : 가희와 수인 분당선 1 (0) | 2022.02.02 |