https://programmers.co.kr/learn/courses/30/lessons/17684
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
vector<int> solution(string msg) {
vector<int> answer;
map<string, int>m_Con;
vector<string> vAlpha = { "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z" };
int mCnt(1);
for (int i = 0; i < vAlpha.size(); i++)
{
m_Con[vAlpha[i]] = mCnt++;
}
int Cut(1);
while (1)
{
if (msg.size() <= 0) break;
string w = msg.substr(0, Cut);
string c = msg.substr(Cut, 1);
string w_c = w + c;
auto tmep_w = m_Con.find(w);
auto tmep_c = m_Con.find(c);
auto tmep_w_c = m_Con.find(w_c);
if (tmep_w != m_Con.end())
{
//여기는
if (tmep_w_c != m_Con.end() && Cut < msg.size())//만약 이 if문 안쓰면 위의 msg.substr(Cut, 1);여기서사망
{
Cut++;
continue;
}
else
{
answer.push_back(tmep_w->second);
m_Con.insert(make_pair(w_c, mCnt++));
msg.erase(0, Cut);
Cut = 1;
}
}
else//끝났을때
{
if (c == "")
{
break;
}
}
}
return answer;
}
int main()
{
string sTep = "KAKAO";
vector<int> vResult = solution(sTep);
//KAKAO[11, 1, 27, 15]
return 0;
}
내가 잘 못하는 문자열 세부조작 유형임.
못풀었음.
string str;
auto temp = string.find(str);
if(temp!=string.end()) Find 함수
w_c내부에 없을때
답에 넣으면서, 내용 추가
있을 때 Cut++;하며 더 길게짜르는 형태.
스트링 연습 더 필요하다.