Coding Test/Baekjoon - Java

11655: ROT13

_jordy 2021. 2. 14. 11:28

www.acmicpc.net/problem/11655

 

11655번: ROT13

첫째 줄에 알파벳 대문자, 소문자, 공백, 숫자로만 이루어진 문자열 S가 주어진다. S의 길이는 100을 넘지 않는다.

www.acmicpc.net

 

a~m까지 13개, m~z까지 13개 


import java.util.*;

public class Main {
    public static String rot13(String s) {
        String ans = "";
        for (int i=0; i<s.length(); i++) {
            
            char c = s.charAt(i);
            
            if (c >= 'a' && c <= 'm') c += 13;   
            else if (c >= 'n' && c <= 'z') c -= 13;   
            else if(c >= 'A' && c <= 'M') c += 13;
            else if(c >= 'N' && c <= 'Z') c -= 13;
            ans += c;
        }
        return ans;
    }
    
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        String st = s.nextLine();
        System.out.println(rot13(st));
    }
}

'Coding Test > Baekjoon - Java' 카테고리의 다른 글

11656: 접미사 배열  (0) 2021.02.14
10824: 네 수  (0) 2021.02.14
2743: 단어 길이 재기  (0) 2021.02.14
10820: 문자열 분석  (0) 2021.02.14
10809: 알파벳 찾기  (0) 2021.02.14