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);
}
|