https://school.programmers.co.kr/learn/courses/30/lessons/155652
글자를 for문으로 ++해간다. 조건문으로 z를 넘어가는지와 skip에 해당하는 글자인지 체크한다. z를넘어가면 a로 돌려주고 skip에 해당하는 글자면 i를 --해준다.
#include <string>
#include <vector>
using namespace std;
string solution(string s, string skip, int index) {
string answer = "";
for(auto& word : s)
{
if(skip.find(word) == string::npos)
for(int i = 0; i < index; i++)
{
word++;
if(word > 'z')
word -= 'z'-'a' + 1;
if(skip.find(word) != string::npos)
i--;
}
}
return s;
}
#include <string>
#include <vector>
using namespace std;
string solution(string s, string skip, int index) {
string answer = "";
for(auto v : s)
{
int t = 0;
int c = v - 'a';
while(t < index)
{
c++;
v = (c % 26) + 'a';
if(skip.find(v) == string::npos)
{
t++;
}
}
answer += v;
}
return answer;
}
char를 int로 변환하여 계산하였다. s를 변환시켜 리턴하지 않고 변환값을 answer에 담아 넘겼다.