프로그래머스 C#/Lv.1
[프로그래머스 C#] 둘만의 암호
썩은피망
2024. 6. 9. 19:52
반응형
문제 살펴보기
- s의 각 알파벳을 index값만큼 더한 값의 알파벳으로 변경합니다.
- 그 과정에서 skip에 포함된 알파벳은 건너띄고 계산합니다.
- 그 결과를 출력하세요.
제한사항
- 1 ≤ terms의 길이 ≤ 20
- 1 ≤ privacies의 길이 ≤ 100
입출력 예
s | skip | index | result |
"aukks" | "wbqd" | 5 | "happy |
using System;
public class Solution {
public string solution(string s, string skip, int index) {
string answer = "";
char[] c = s.ToCharArray();
char[] sk = skip.ToCharArray();
for(int x = 0; x < c.Length; x++)
{
for(int i = 0; i < index; i++)
{
c[x] = Convert.ToChar(c[x] + 1);
if(c[x] == '{') c[x] = 'a';
if(Array.IndexOf(sk, c[x]) != -1) i--;
}
}
answer = new string(c);
return answer;
}
}
반응형