CodeSignal/Arcade
CodeSignal [28/60] alphabeticShift
벤진[Benzene]
2020. 5. 19. 03:33
문제: Given a string, your task is to replace each of its characters by the next one in the English alphabet; i.e. replace a with b, replace b with c, etc (z would be replaced by a).
Example
For inputString = "crazy", the output should be alphabeticShift(inputString) = "dsbaz".
-문제해결 정리-
1. inputString에서 각 알파벳의 바꾼 값을 넣어줄 ans_list 를 만들어 준다.
2. inputString안에 있는 각 알파벳을 loop을 돌며 ascii code 값에서 +1 을 해준후에 다시 캐릭터로 바꾸어 ans_list 안에 넣어준다. (단, 알파벳이 z일때는 +1 을 해주지 않고 바로 'a' 값을 넣어준다.)
3. 모든 알파벳을 다음 알파벳으로 바꾼 ans_list를 정답의 포맷에 맞추어 .join()함수를 써서 string으로 변환후 리턴.
모든 문제에 대한 저작권은 CodeSignal 회사에 있습니다. [Copyright © 2020 BrainFights Inc. All rights reserved]