๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“ ์•Œ๊ณ ๋ฆฌ์ฆ˜/Programmers

[C++/PGS] Lv.1 : ๋™์˜์ƒ ์žฌ์ƒ๊ธฐ (PCCP ๊ธฐ์ถœ๋ฌธ์ œ 1๋ฒˆ)

by xxilliant 2025. 5. 2.
728x90
๋ฐ˜์‘ํ˜•

 

https://school.programmers.co.kr/learn/courses/30/lessons/340213

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

SW๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ ํ‰๊ฐ€, ๊ต์œก, ์ฑ„์šฉ๊นŒ์ง€ Total Solution์„ ์ œ๊ณตํ•˜๋Š” ๊ฐœ๋ฐœ์ž ์„ฑ์žฅ์„ ์œ„ํ•œ ๋ฒ ์ด์Šค์บ ํ”„

programmers.co.kr


ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ๋ ˆ๋ฒจ 1..์ž„์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ  ์ •๋‹ต๋ฅ ์ด 37%๋กœ ๊ฝค๋‚˜ ๋‚ฎ์€ ๋ฌธ์ œ.

์†Œ์š”์‹œ๊ฐ„ ์•ฝ 22๋ถ„

 

๊ธฐ๋ณธ์ ์ธ ๋ฌธ์ž์—ด ๋‹ค๋ฃจ๊ธฐ ๋ฌธ์ œ์ด์ง€๋งŒ,

์˜คํžˆ๋ ค ์•„์ฃผ ๊ธฐ์ดˆ์ ์ธ ๋ฌธ๋ฒ•์„ ๋‹ค๋ค„์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์—

์žŠ๊ณ  ์žˆ์—ˆ๋˜ ๋‚ด์šฉ๋„ ์žˆ์—ˆ๊ณ  ๋งŽ์ด ํ—ท๊ฐˆ๋ ค์„œ ์ƒ๊ฐ๋ณด๋‹ค ์˜ค๋ž˜ ๊ฑธ๋ ธ๋‹ค ใ…‹ใ…‹ ๊ผญ ๊ธฐ์–ตํ•ด๋‘๊ธฐ~~!!!!

 

 

(c++ ๊ธฐ์ค€ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•)

์‹œ๊ฐ„์„ ๋ชจ๋‘ ์ดˆ ๋‹จ์œ„๋กœ ๋ฐ”๊ฟ”์ค„ ๋•Œ, ๊ฐ ๋ฌธ์ž๋งˆ๋‹ค [ ๋ฌธ์ž-'0' ]์„ ํ•ด์ค€ ๋‹ค์Œ ์—ฐ์‚ฐํ•ด์•ผ ํ•˜๊ณ 

๋”ํ•  ๋•Œ๋Š” string์œผ๋กœ [๋ฌธ์ž+'0']์„ ์—ฐ์‚ฐํ•ด์ฃผ๊ฑฐ๋‚˜, to_string์„ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

 

1๏ธโƒฃ string์œผ๋กœ ๋ช…์‹œ์  ํ˜•๋ณ€ํ™˜

answer += string(1, h/10+'0') + string(1, h%10+'0');
answer += to_string(h / 10) + to_string(h % 10);

 

 

 

๋‚˜์˜ ํ’€์ด

#include <string>
#include <vector>
#include <iostream>
using namespace std;

int timeToSec(string t) {
    return ((t[0]-'0')*10 + (t[1]-'0'))*60 + ((t[3]-'0')*10+(t[4]-'0'));
}

string solution(string video_len, string pos, string op_start, string op_end, vector<string> commands) {
    string answer = "";
    int len = timeToSec(video_len);
    int nowSec = timeToSec(pos);
    int opStart = timeToSec(op_start);
    int opEnd = timeToSec(op_end);
    
    for(string command: commands){
        if(nowSec >= opStart && nowSec < opEnd) nowSec = opEnd;
        if(command == "next"){
            nowSec += 10;
            if(nowSec > len) nowSec = len;
        }
        if(command == "prev"){
            nowSec -= 10;
            if(nowSec < 0) nowSec = 0;
        }
    }
    if(nowSec >= opStart && nowSec < opEnd) nowSec = opEnd;
    int h = nowSec/60;
    int m = nowSec%60;
    answer += to_string(h / 10) + to_string(h % 10);
    answer += ":";
    answer += to_string(m / 10) + to_string(m % 10);
    
    return answer;
}

728x90
๋ฐ˜์‘ํ˜•