C++/programmers 코딩테스트(level 1) C++

[C/C++] programmers Level 1 둘만의 암호

CE : 하랑 2023. 11. 5. 20:19

 

 

 

 

 

코드

 

#include <string> // find
#include <algorithm> 

using namespace std;

string solution(string s, string skip, int index) {
    
    string answer = "";
    
    for(int i=0;i<s.size();i++){
        
        char alp=s[i];
        
        for(int j=0;j<index;){
            alp++; // index 크기만큼 알파벳 이동
            
            if(alp=='z'+1){ // z 이후의 연산이 진행될 경우 a로 시작
                alp='a';
            }
            
            if(skip.find(alp)==string::npos){ // skip 문자열에 alp 문자가 없는 경우만 j++
                j++;
            }
        }
        
        answer=answer+alp; 
    }
    return answer;
}