https://school.programmers.co.kr/learn/courses/30/lessons/92341
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
using namespace std;
int time_diff(string in, string out) {
int h1 = stoi(in.substr(0, 2));
int m1 = stoi(in.substr(3, 2));
int h2 = stoi(out.substr(0, 2));
int m2 = stoi(out.substr(3, 2));
int diff = (h2-h1)*60 + (m2-m1);
return diff;
}
vector<int> solution(vector<int> fees, vector<string> records) {
vector<int> answer;
map<string, vector<string>> m;
stringstream ss;
for(auto record: records) {
ss.str(record);
string time, number, status; ss >> time >> number >> status;
m[number].push_back(time);
ss.clear();
}
for(auto it: m) {
if(it.second.size() & 1) // 주차 내역 홀수면 "23:59" 추가
it.second.push_back("23:59");
vector<string> info = it.second;
int total = 0;
for(int i=0; i<info.size()-1; i+=2) {
total += time_diff(info[i], info[i+1]);
}
int price = fees[1];
if(total > fees[0]) {
price += ceil((total-fees[0]) / (double)fees[2]) * fees[3];
}
answer.push_back(price);
}
return answer;
}
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] Lv 2. 땅따먹기 (0) | 2023.07.09 |
---|---|
[Programmers] (2019 KAKAO BLIND RECRUITMENT) Lv 2. 오픈채팅방 (0) | 2023.07.09 |
[Programmers] (힙(Heap)) Lv 2. 더 맵게 (0) | 2023.07.04 |
[Programmers] (2018 KAKAO BLIND RECRUITMENT) Lv 2. [3차] n진수 게임 (0) | 2023.07.03 |
[Programmers] (2018 KAKAO BLIND RECRUITMENT) Lv 2. [3차] 압축 (0) | 2023.07.03 |
댓글