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
| #include <string.h>
#include <vector>
#include <sstream>
#include <iostream>
using namespace std;
void convertCode(string &code)
{
while (!(code.find("A#") == string::npos &&
code.find("C#") == string::npos &&
code.find("D#") == string::npos &&
code.find("F#") == string::npos &&
code.find("G#") == string::npos))
{
if (code.find("A#") != string::npos) { code.replace(code.find("A#"), 2, "H"); }
else if (code.find("C#") != string::npos) { code.replace(code.find("C#"), 2, "I"); }
else if (code.find("D#") != string::npos) { code.replace(code.find("D#"), 2, "J"); }
else if (code.find("F#") != string::npos) { code.replace(code.find("F#"), 2, "K"); }
else if (code.find("G#") != string::npos) { code.replace(code.find("G#"), 2, "L"); };
}
}
string solution(string m, vector<string> musicinfos) {
string answer = "";
int beforePlaytime = 0;
convertCode(m);
for (auto& music : musicinfos)
{
stringstream ss(music);
char comma, colon;
int starthour, endhour;
int startminute, endminute;
string songnameAndCode;
string songname;
string code;
//03:00,03:30,FOO,CC#B
//시간 받기
ss >> starthour >> colon >> startminute >> comma >> endhour >> colon >> endminute >> comma >> songnameAndCode;
ss.str(songnameAndCode); ss.clear();
getline(ss, songname, ','); getline(ss, code, '\0'); ss.str(""); ss.clear();
int playtime = (60 * (endhour - starthour))
+ (endminute - startminute);
//code에 있는 #을 치환
//A# -> H, C# -> I, D# -> J, F# -> K, G# ->L
convertCode(code);
int songtime = (int)code.size();
string listenCode;
//오류지점으로 보임
for (int i = 0; i < playtime; i++)
listenCode += code[i % songtime];
//확인
string::size_type check;
check = listenCode.find(m);
//문자열이 존재하고 전에 넣었던 answer에 비해 노래제목이 긴 노래 넣기
if (check != string::npos)
if (playtime > beforePlaytime)
{
answer = songname;
beforePlaytime = playtime;
}
}
if (answer.size() == 0)
answer = "(None)";
return answer;
}
|