๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ์ธ๊ณต๋ถ€/Algorithm

[๋ฐฑ์ค€][Node.js] 5598๋ฒˆ : ์นด์ด์‚ฌ๋ฅด ์•”ํ˜ธ

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2021. 11. 28.

 

 

Algorithm

-  ์นด์ด์‚ฌ๋ฅด ์•”ํ˜ธ -

 


 

๋ฌธ์ œ

๊ฐ€์ด์šฐ์Šค ์œจ๋ฆฌ์šฐ์Šค ์นด์ด์‚ฌ๋ฅด(Gaius Julius Caesar)๋Š” ๊ณ ๋Œ€ ๋กœ๋งˆ ๊ตฐ์ธ์ด์ž ์ •์น˜๊ฐ€์˜€๋‹ค. ์นด์ด์‚ฌ๋ฅด๋Š” ๋น„๋ฐ€์Šค๋Ÿฝ๊ฒŒ ํŽธ์ง€๋ฅผ ์“ธ ๋•Œ, 'A'๋ฅผ 'D๋กœ', 'B'๋ฅผ 'E'๋กœ, 'C'๋ฅผ 'F'๋กœ... ์ด๋Ÿฐ ์‹์œผ๋กœ ์•ŒํŒŒ๋ฒณ ๋ฌธ์ž๋ฅผ 3๊ฐœ์”ฉ ๊ฑด๋„ˆ๋›ฐ์–ด ์ ์—ˆ๋‹ค๊ณ  ํ•œ๋‹ค.

26๊ฐœ์˜ ๋Œ€๋ฌธ์ž ์•ŒํŒŒ๋ฒณ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๋‹จ์–ด๋ฅผ ์นด์ด์‚ฌ๋ฅด ์•”ํ˜ธ ํ˜•์‹์œผ๋กœ 3๋ฌธ์ž๋ฅผ ์˜ฎ๊ฒจ ๊ฒน์น˜์ง€ ์•Š๊ฒŒ ๋‚˜์—ดํ•˜์—ฌ ์–ป์€ ์นด์ด์‚ฌ๋ฅด ๋‹จ์–ด๊ฐ€ ์žˆ๋‹ค. ์ด ์นด์ด์‚ฌ๋ฅด ๋‹จ์–ด๋ฅผ ์›๋ž˜ ๋‹จ์–ด๋กœ ๋Œ๋ ค๋†“๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

๊ฐ ๋ฌธ์ž๋ณ„๋กœ ๋ณ€ํ™˜ ์ „๊ณผ ๋ณ€ํ™˜ ํ›„๋ฅผ ๋‚˜ํƒ€๋‚ธ ๊ฑด ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

๋ณ€ํ™˜์ „    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 
๋ณ€ํ™˜ํ›„    D E F G H I J K L M N O P Q R S T U V W X Y Z A B C

์˜ˆ๋ฅผ ๋“ค์–ด์„œ, ์ด ๋ฐฉ๋ฒ•๋Œ€๋กœ ๋‹จ์–ด 'JOI'๋ฅผ ์นด์ด์‚ฌ๋ฅด ๋‹จ์–ด ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค๋ฉด 'MRL'์„ ์–ป์„ ์ˆ˜ ์žˆ๊ณ , ์•ž์˜ ์˜ˆ์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ ์–ป์€ ์นด์ด์‚ฌ๋ฅด ๋‹จ์–ด 'FURDWLD'๋ฅผ ์›๋ž˜ ๋‹จ์–ด๋กœ ๊ณ ์น˜๋ฉด 'CROATIA'๊ฐ€ ๋œ๋‹ค.

 

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

๋ฌธ์ œ ํ’€๊ธฐ

let fs = require("fs");
let input = fs.readFileSync("/dev/stdin").toString().trim();
let alpha = "abcdefghijklmnopqrstuvwxyz".toUpperCase().split("");
let result = "";

for (let i = 0; i < input.length; i++) {
	if (alpha.indexOf(input[i]) <= 2) {
		result += alpha[alpha.indexOf(input[i]) + 26 - 3];
	} else result += alpha[alpha.indexOf(input[i]) - 3];
}

console.log(result);

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€