From 8938959d7c326fc2008f2dceb1c530fa93ef1230 Mon Sep 17 00:00:00 2001 From: kangrae Date: Sat, 11 Jan 2025 20:00:58 +0900 Subject: [PATCH] =?UTF-8?q?2025-01-11=20=EB=8F=99=EC=98=81=EC=83=81=20?= =?UTF-8?q?=EC=9E=AC=EC=83=9D=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kangrae-jo/README.md | 2 +- .../15-kangrae-jo.cpp" | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 "kangrae-jo/\352\265\254\355\230\204/15-kangrae-jo.cpp" diff --git a/kangrae-jo/README.md b/kangrae-jo/README.md index 34ad789..2f48722 100644 --- a/kangrae-jo/README.md +++ b/kangrae-jo/README.md @@ -15,5 +15,5 @@ | 11차시 | 2024.12.21 | Greedy | [ATM](https://www.acmicpc.net/problem/11399)|[#41](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/41)| | 12차시 | 2024.12.24 | HEAP | [크리스마스 선물](https://www.acmicpc.net/problem/14235)|[#44](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/44)| | 13차시 | 2024.12.28 | Graph | [줄 세우기](https://www.acmicpc.net/problem/2252)|[#46](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/46)| - +| 15차시 | 2024.12.28 | 구현 | [동영상 재생기](https://school.programmers.co.kr/learn/courses/30/lessons/340213?language=cpp)|[#57](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/57)| --- diff --git "a/kangrae-jo/\352\265\254\355\230\204/15-kangrae-jo.cpp" "b/kangrae-jo/\352\265\254\355\230\204/15-kangrae-jo.cpp" new file mode 100644 index 0000000..6d2c27c --- /dev/null +++ "b/kangrae-jo/\352\265\254\355\230\204/15-kangrae-jo.cpp" @@ -0,0 +1,69 @@ +#include +#include + +using namespace std; + +struct Time { + int m, s; +}; + +string solution(string video_len, string pos, string op_start, string op_end, vector commands) { + Time video_len_, pos_, op_start_, op_end_; + + // string to int (time) + video_len_.m = (video_len[0] - '0') * 10 + (video_len[1] - '0'); + video_len_.s = (video_len[3] - '0') * 10 + (video_len[4] - '0'); + pos_.m = (pos[0] - '0') * 10 + (pos[1] - '0'); + pos_.s = (pos[3] - '0') * 10 + (pos[4] - '0'); + op_start_.m = (op_start[0] - '0') * 10 + (op_start[1] - '0'); + op_start_.s = (op_start[3] - '0') * 10 + (op_start[4] - '0'); + op_end_.m = (op_end[0] - '0') * 10 + (op_end[1] - '0'); + op_end_.s = (op_end[3] - '0') * 10 + (op_end[4] - '0'); + + // 오프닝 건너뛰기 + if (op_start_.m * 60 + op_start_.s <= pos_.m * 60 + pos_.s && + op_end_.m * 60 + op_end_.s > pos_.m * 60 + pos_.s) { + pos_.m = op_end_.m; + pos_.s = op_end_.s; + } + + // command 실행 + for (string command : commands) { + if (command == "next") { + pos_.s += 10; + if (pos_.s >= 60) { + pos_.s -= 60; + pos_.m += 1; + } + if (video_len_.m * 60 + video_len_.s <= pos_.m * 60 + pos_.s) { + pos_.m = video_len_.m; + pos_.s = video_len_.s; + } + } + else if (command == "prev") { + pos_.s -= 10; + if (pos_.s < 0) { + pos_.s += 60; + pos_.m -= 1; + } + if (pos_.m < 0) { + pos_.m = 0; + pos_.s = 0; + } + } + // 오프닝 건너뛰기 + if (op_start_.m * 60 + op_start_.s <= pos_.m * 60 + pos_.s && + op_end_.m * 60 + op_end_.s > pos_.m * 60 + pos_.s) { + pos_.m = op_end_.m; + pos_.s = op_end_.s; + } + } + + string answer = ""; + if (pos_.m < 10) answer += "0"; + answer += to_string(pos_.m) + ":"; + if (pos_.s < 10) answer += "0"; + answer += to_string(pos_.s); + + return answer; +} \ No newline at end of file