Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

15-kangrae-jo #57

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kangrae-jo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)|
---
69 changes: 69 additions & 0 deletions kangrae-jo/๊ตฌํ˜„/15-kangrae-jo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <string>
#include <vector>

using namespace std;

struct Time {
int m, s;
};

string solution(string video_len, string pos, string op_start, string op_end, vector<string> 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;
}
Loading