강의로 돌아가기
구경잘함

c++ 제출시의 테스트케이스 1번 실패...

제출시의 1번 케이스가 안뚫리는데 제가 어딜 놓쳤을까요...... 너무 코드를 막썻나 싶어서 다시 봐도 이상한건 몰?루겠는데..
혹시 반례를 알려주시면 해보겠습니다.

작성중인 코드―solution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <string>
#include <vector>

using namespace std;

int CharToInt(char cTimeChar);
int StringTimeToIntSec(string stringTime);
string IntSecToStringTime(int second);

string solution(string video_len, string pos, string op_start, string op_end, vector<string> commands) {
    string answer = "";

    int videoLen = StringTimeToIntSec(video_len);
    int currentPos = StringTimeToIntSec(pos);
    int opStartPos = StringTimeToIntSec(op_start);
    int opEndPos = StringTimeToIntSec(op_end);

    for (auto command : commands)
    {
        if (opStartPos <= currentPos && currentPos <= opEndPos)
        {
            currentPos = opEndPos;
        }

        if (command == "next")
        {
            bool bCheck = false;

            if (opStartPos <= currentPos + 10 && currentPos <= opEndPos)
            {
                if(opEndPos - currentPos > 10)
                {
                    bCheck = true;
                }

                currentPos = opEndPos;
            }

            if(!bCheck)
            {
                currentPos += 10;   
            }
        }
        else if (command == "prev")
        {
            currentPos -= 10; 
        }

        if (currentPos < 0)
        {
            currentPos = 0;
        }

        if (currentPos > videoLen-10)
        {
            currentPos = videoLen;
        }
    }    

    return IntSecToStringTime(currentPos);
}

int CharToInt(char cTimeChar)
{
    return cTimeChar - '0';
}

int StringTimeToIntSec(string stringTime)
{
    return ((CharToInt(stringTime[0]) * 10 + CharToInt(stringTime[1])) * 60) + (CharToInt(stringTime[3]) * 10 + CharToInt(stringTime[4]));
}

string IntSecToStringTime(int second)
{
    int iMinute = second / 60;
    char cFirstChar = iMinute / 10 + '0';
    char cSecondChar = iMinute % 10 + '0';

    int iSecond = second % 60;
    char cThirdChar = iSecond / 10 + '0';
    char cFourthChar = iSecond % 10 + '0';

    char tempArray[5 + 1];
    //memset(tempArray, 0x00, 5 + 1);

    tempArray[0] = cFirstChar;
    tempArray[1] = cSecondChar;
    tempArray[2] = ':';
    tempArray[3] = cThirdChar;
    tempArray[4] = cFourthChar;

    tempArray[5] = 0x00;

    return string(tempArray);
}

1 개의 답변
낙방여우

반례입니다.
입력값 〉 "30:00", "01:05", "01:00", "01:30", ["prev"]
기댓값 〉 "01:30"

  • 구경잘함

    아... prev에서도 건너뛰기가 실행되어야 하는군요... 문제 이해를 잘못했나보네요 감사합니다 ㅎㅎ

    구경잘함―2024.11.20 04:22
답변 쓰기
이 입력폼은 마크다운 문법을 지원합니다.