해맑은욱 2019. 9. 5. 16:47
* 시저암호(string
각 알파벳을 일정한 거리만큼 밀어서 다른 알파벳으로 바꿈. 
- A, z - a 로 바뀜. 공백은 공백. 
 
#include <iostream>
#include <string>
 
using namespace std
 
string solution(string s, int n) { 
    string answer = ""
     
    int pos; 
    for(int i = 0; i < s.size(); i++
    { 
        if(s[i] == ' '
            answer += ' '
        else 
        { 
            pos = (s[i] >= 'a') ? 'a' : 'A'
            answer += pos + (s[i] - pos + n) % 26
        } 
    } 
     
    return answer; 
cs