๐ŸŒˆ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ๋Œ€์†Œ๋ฌธ์ž ๋ฐ”๊ฟ”์„œ ์ถœ๋ ฅํ•˜๊ธฐ

Eun_zii 2024. 4. 11. 17:43

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0

- ๋Œ€์†Œ๋ฌธ์ž ๋ฐ”๊ฟ”์„œ ์ถœ๋ ฅํ•˜๊ธฐ

 

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

 

๐Ÿ’š ์ œํ•œ์กฐ๊ฑด

  • 1 ≤ str์˜ ๊ธธ์ด ≤ 20
    • str์€ ์•ŒํŒŒ๋ฒณ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค.

๐Ÿ’š ํ’€์ด

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let input = [];

rl.on('line', function (line) {
    input = [line];
}).on('close',function(){
    str = input[0];
    let answer = ""
    for ( let i = 0; i < str.length; i++) {
        const newStr = str[i];
         if (newStr === newStr.toUpperCase()) {
            answer += newStr.toLowerCase();
        } else {
            answer += newStr.toUpperCase();
        }
    }
    console.log(answer);
});

 

โœ… 

let answer = ""

 : ๊ฒฐ๊ณผ๋ฅผ ๋‹ด์„ ๋นˆ ๋ฌธ์ž์—ด์„ ๋งŒ๋“ค์–ด๋‘๊ณ , 
for ( let i = 0; i < str.length; i++) {

 : ๊ฐ ๋ฌธ์ž๋ฅผ ์ˆœํšŒํ•˜๋ฉด ํ™•์ธ

const newStr = str[i];
if (newStr === newStr.toUpperCase()) {
answer += newStr.toLowerCase();
} else {
answer += newStr.toUpperCase();
}}

 : str์˜ ๊ฐ ์›์†Œ๊ฐ€ ๋Œ€๋ฌธ์ž์ธ์ง€ ํ™•์ธํ•˜๊ณ  ๋Œ€๋ฌธ์ž ๋ผ๋ฉด ์†Œ๋ฌธ์ž๋กœ ์•„๋‹ˆ๋ฉด ๋Œ€๋ฌธ์ž๋กœ answer์— ๋‹ด์•„๋‘”๋‹ค.
console.log(answer);

 : ๋‹ด์•„๋‘” answer๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

728x90