Skip to content

Instantly share code, notes, and snippets.

@mingyu-lee
Created August 21, 2018 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mingyu-lee/674110253e66055c4783a3acff09769d to your computer and use it in GitHub Desktop.
Save mingyu-lee/674110253e66055c4783a3acff09769d to your computer and use it in GitHub Desktop.
BOJ_11655_ROT13
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);
}
}
@mingyu-lee
Copy link
Author

좀더 간결하게 할 수 있는 방법이 있을까...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment