Created
August 21, 2018 14:22
-
-
Save mingyu-lee/674110253e66055c4783a3acff09769d to your computer and use it in GitHub Desktop.
BOJ_11655_ROT13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
public class ROT13 { | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
char[] chars = br.readLine().trim().toCharArray(); | |
int len = chars.length; | |
char[] resultChars = new char[len]; | |
for (int i = 0; i < len; i++) { | |
char tempChar = chars[i]; | |
int charCode = (int) tempChar; | |
// 알파벳 대문자 | |
if (65 <= charCode && charCode <= 90) { | |
if (charCode + 13 > 90) { | |
resultChars[i] = (char)(65 + (13 - (90-charCode)) - 1); | |
} else { | |
resultChars[i] = (char)(charCode + 13); | |
} | |
// 알파벳 소문자 | |
} else if (97 <= charCode && charCode <= 122) { | |
if (charCode + 13 > 122) { | |
resultChars[i] = (char)(97 + (13 - (122-charCode)) - 1); | |
} else { | |
resultChars[i] = (char)(charCode + 13); | |
} | |
} else { | |
resultChars[i] = tempChar; | |
} | |
} | |
System.out.println(resultChars); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
좀더 간결하게 할 수 있는 방법이 있을까...