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
|
#include <string>
#include <vector>
using namespace std;
string solution(string s, int n) {
string answer = "";
for(int i = 0 ; i < s.size() ; i++)
{
//공백 처리
if(s[i] == ' ')
{
answer += " ";
continue;
}
//아스키코드 변환
int ascii = s[i];
for(int j = 0 ; j < n ; j++)
{
ascii++;
if(ascii == 'z' +1 || ascii == 'Z' +1)
ascii -= 26;
}
answer += ascii;
}
return answer;
}
|
문자를 ascii 코드로 변환해 코드의 값을 비교해서 문제 해결
'코딩테스트 연습' 카테고리의 다른 글
코딩 테스트 - 최대값과 최솟값 (0) | 2020.01.14 |
---|---|
코딩테스트 - 약수의 합 (0) | 2020.01.14 |
코딩 테스트 - 문자열을 정수로 바꾸기 (0) | 2020.01.13 |
코딩테스트 - 소수 찾기 (0) | 2020.01.13 |
코딩테스트 - 문자열 내림차순으로 배치하기 (0) | 2020.01.13 |