문제
c
Assignment name : rot_13
Expected files : rot_13.c
Allowed functions: write
--------------------------------------------------------------------------------
Write a program that takes a string and displays it, replacing each of its
letters by the letter 13 spaces ahead in alphabetical order.
'z' becomes 'm' and 'Z' becomes 'M'. Case remains unaffected.
The output will be followed by a newline.
If the number of arguments is not 1, the program displays a newline.
Example:
$>./rot_13 "abc"
nop
$>./rot_13 "My horse is Amazing." | cat -e
Zl ubefr vf Nznmvat.$
$>./rot_13 "AkjhZ zLKIJz , 23y " | cat -e
NxwuM mYXVWm , 23l $
$>./rot_13 | cat -e
$
$>
$>./rot_13 "" | cat -e
$
$>
주의점
-
바꾸는 방법만 잘 알아두자
str[i] = (str[i] - ‘a’ + 13) % 26 + ‘a’ -
‘a’를 빼서 원래 아스키를 알파벳 번호로 바꾼다
-
13을 더해야 문제 조건 파악
-
모듈러 26을 해야 제대로 나머지를 파악 가능
- 26 = 알파벳 갯수
-
다시 ‘a’를 더해서 알파벳 번호 ⇒ 아스키 코드