01-10 04:27
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[BAEKJOON] ๋ฐฑ์ค€ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ11655 :: ROT13 JAVA ๋ณธ๋ฌธ

Algorithm/Baekjoon

[BAEKJOON] ๋ฐฑ์ค€ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ11655 :: ROT13 JAVA

miinsun 2022. 3. 15. 20:09

 

๐Ÿ’ฌ  ๋ฌธ์ œ ์„ค๋ช…

ROT13์€ ์นด์ด์‚ฌ๋ฅด ์•”ํ˜ธ์˜ ์ผ์ข…์œผ๋กœ ์˜์–ด ์•ŒํŒŒ๋ฒณ์„ 13๊ธ€์ž์”ฉ ๋ฐ€์–ด์„œ ๋งŒ๋“ ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, "Baekjoon Online Judge"๋ฅผ ROT13์œผ๋กœ ์•”ํ˜ธํ™”ํ•˜๋ฉด "Onrxwbba Bayvar Whqtr"๊ฐ€ ๋œ๋‹ค.
ROT13์œผ๋กœ ์•”ํ˜ธํ™”ํ•œ ๋‚ด์šฉ์„ ์›๋ž˜ ๋‚ด์šฉ์œผ๋กœ ๋ฐ”๊พธ๋ ค๋ฉด ์•”ํ˜ธํ™”ํ•œ ๋ฌธ์ž์—ด์„ ๋‹ค์‹œ ROT13ํ•˜๋ฉด ๋œ๋‹ค.
์•ž์—์„œ ์•”ํ˜ธํ™”ํ•œ ๋ฌธ์ž์—ด "Onrxwbba Bayvar Whqtr"์— ๋‹ค์‹œ ROT13์„ ์ ์šฉํ•˜๋ฉด "Baekjoon Online Judge"๊ฐ€ ๋œ๋‹ค.

ROT13์€ ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž์™€ ์†Œ๋ฌธ์ž์—๋งŒ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์•ŒํŒŒ๋ฒณ์ด ์•„๋‹Œ ๊ธ€์ž๋Š” ์›๋ž˜ ๊ธ€์ž ๊ทธ๋Œ€๋กœ ๋‚จ์•„ ์žˆ์–ด์•ผ ํ•œ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด, "One is 1"์„ ROT13์œผ๋กœ ์•”ํ˜ธํ™”ํ•˜๋ฉด "Bar vf 1"์ด ๋œ๋‹ค.

๋ฌธ์ž์—ด์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, "ROT13"์œผ๋กœ ์•”ํ˜ธํ™”ํ•œ ๋‹ค์Œ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

 

๐Ÿ”จ  ์ž…์ถœ๋ ฅ ์˜ˆ

์ž…๋ ฅ 

  • ์ฒซ์งธ ์ค„์— ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž, ์†Œ๋ฌธ์ž, ๊ณต๋ฐฑ, ์ˆซ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด S๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.
  • S์˜ ๊ธธ์ด๋Š” 100์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค.

 

์ถœ๋ ฅ

  • ์ฒซ์งธ ์ค„์— S๋ฅผ ROT13์œผ๋กœ ์•”ํ˜ธํ™”ํ•œ ๋‚ด์šฉ์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1)

Baekjoon Online Judge

 

์˜ˆ์ œ ์ถœ๋ ฅ 1)

Onrxwbba Bayvar Whqtr

 

์˜ˆ์ œ ์ž…๋ ฅ 2)

One is 1

 

์˜ˆ์ œ ์ถœ๋ ฅ 2)

Bar vf 1

 

โ€‹

๐Ÿ’ป  Main.java

/* ๋ฐฑ์ค€ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ - 11655 :: ROT13 */
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();

		for(char c : s.toCharArray()) {
			if(Character.isAlphabetic(c)) {
				int tmp = 0;
				if(Character.isUpperCase(c)) {
					if(c + 13 > 'Z')	{
						tmp = (12 - ('Z' - c)) + 'A';
						System.out.print((char) tmp);
					}
					else
						System.out.print((char)(c + 13));
				}
				else if(Character.isLowerCase(c)) {
					if(c + 13 > 'z')	{
						tmp = (12 - ('z' - c)) + 'a';
						System.out.print((char)tmp);
					}
					else
						System.out.print((char) (c + 13));
				}
				
			}
			else
				System.out.print(c);
		}
		sc.close();
	}
}
Comments