[Java] 백준11655번 ROT13
2022. 4. 7. 22:38
728x90
https://www.acmicpc.net/problem/11655
이번 문제는 13씩 더하고 알파벳 숫자를 벗어나면 처음부터 다시 남은 수를 더해주면 풀리는 문제입니다.
package BJ;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BJ_ROT13 {
static String str;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
str = br.readLine();
for (int i = 0; i < str.length(); i++) {
int a = str.charAt(i);
if(a >= 65 && a <= 90) {
a += 13;
if(a > 90) {
int b = a - 91;
a = 65+b;
}
} else if (a >= 97 && a <= 122) {
a += 13;
if(a > 122) {
int b = a-123;
a = 97 + b;
}
}
sb.append((char)a);
}
System.out.println(sb.toString());
}
}
Ysik Github : https://github.com/Y1sik/Algorithm/blob/main/BJ/BJ_ROT13.java
반응형
'알고리즘' 카테고리의 다른 글
[Java] 백준 10820번 문자열 분석 (0) | 2022.04.09 |
---|---|
[Java] 백준 5430번 AC (0) | 2022.04.08 |
[Java] 백준10798번 세로읽기 (0) | 2022.04.06 |
[Java] 백준 9093번 단어 뒤집기 (0) | 2022.04.05 |
[Java] 백준 10988번 팰린드롬인지 확인하기 (0) | 2022.04.04 |