diff --git a/kangrae-jo/README.md b/kangrae-jo/README.md index 3fd6751..735c043 100644 --- a/kangrae-jo/README.md +++ b/kangrae-jo/README.md @@ -16,5 +16,6 @@ | 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)| | 14차시 | 2024.12.31 | Two Pointer | [두 용액](https://www.acmicpc.net/problem/2470)|[#48](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/48)| +| 15차시 | 2024.01. | 구현 | [동영상 재생기](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