๊ด€๋ฆฌ ๋ฉ”๋‰ด

Daehyunii's Dev-blog

์œ ํšจํ•œ ํŒฐ๋ฆฐ๋“œ๋กฌ(๋ฌธ์ž์—ด ํƒ์ƒ‰) ๋ณธ๋ฌธ

๐Ÿ“š Language & CS knowledge/Algorithm (๊ธฐ์ดˆ๋ฌธ์ œํ’€์ด)

์œ ํšจํ•œ ํŒฐ๋ฆฐ๋“œ๋กฌ(๋ฌธ์ž์—ด ํƒ์ƒ‰)

Daehyunii 2022. 8. 31. 23:51

๋ฌธ์ œ(์ถœ์ฒ˜ : ์ธํ”„๋Ÿฐ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œํ’€์ด ๊ฐ•์˜, ์ •๋ณด์˜ฌ๋ฆผํ”ผ์•„๋“œ)

 

์•ž์—์„œ ์ฝ์„ ๋•Œ๋‚˜ ๋’ค์—์„œ ์ฝ์„ ๋•Œ๋‚˜ ๊ฐ™์€ ๋ฌธ์ž์—ด์„ ํŒฐ๋ฆฐ๋“œ๋กฌ์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.๋ฌธ์ž์—ด์ด ์ž…๋ ฅ๋˜๋ฉด ํ•ด๋‹น ๋ฌธ์ž์—ด์ด ํŒฐ๋ฆฐ๋“œ๋กฌ์ด๋ฉด "YES", ์•„๋‹ˆ๋ฉด “NO"๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์„ธ์š”.๋‹จ ํšŒ๋ฌธ์„ ๊ฒ€์‚ฌํ•  ๋•Œ ์•ŒํŒŒ๋ฒณ๋งŒ ๊ฐ€์ง€๊ณ  ํšŒ๋ฌธ์„ ๊ฒ€์‚ฌํ•˜๋ฉฐ, ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์•ŒํŒŒ๋ฒณ ์ด์™ธ์˜ ๋ฌธ์ž๋“ค์˜ ๋ฌด์‹œํ•ฉ๋‹ˆ๋‹ค.

โ–ฃ ์ž…๋ ฅ์„ค๋ช…
์ฒซ ์ค„์— ์ •์ˆ˜ ๊ธธ์ด 100์„ ๋„˜์ง€ ์•Š๋Š” ๊ณต๋ฐฑ์ด ์—†๋Š” ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.

โ–ฃ ์ถœ๋ ฅ์„ค๋ช…
์ฒซ ๋ฒˆ์งธ ์ค„์— ํŒฐ๋ฆฐ๋“œ๋กฌ์ธ์ง€์˜ ๊ฒฐ๊ณผ๋ฅผ YES ๋˜๋Š” NO๋กœ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

 

โ–ฃ ์ž…๋ ฅ์˜ˆ์ œ 1
found7, time: study; Yduts; emit, 7Dnuof

 

โ–ฃ ์ถœ๋ ฅ์˜ˆ์ œ 1

YES

 

 

Tip

 

๋ฌธ์ œํ’€์ด

// ๋ฉ”์„œ๋“œ๋ฅผ ํ™œ์šฉํ•ด์„œ ์ž‘์„ฑํ•˜๊ธฐ (์ •๋‹ต๋ณด๊ณ  ๋‚ด๊ฐ€ ์ž‘์„ฑ)
function solution(str){
    let result = "YES"
    let temp = str.toLowerCase().replace(/[^a-z]/g, '')
    if(temp.split('').reverse().join('') !== temp) return "NO"
    return result;
}

 let str2="found7, time: study; Yduts; emit, 7Dnuof";
console.log(solution(str2));



// for๋ฌธ์œผ๋กœ ์ž‘์„ฑํ•˜๊ธฐ (์ •๋‹ต๋ณด๊ณ  ๋‚ด๊ฐ€ ์ž‘์„ฑ)
function solution(string){
    let result = "YES";
    let temp = string.toLowerCase().replace(/[^a-z]/g, '');
    let len = temp.length;

    for(let i = 0 ; i < Math.floor(len / 2) ; i++){
        if(temp[i] !== temp[len-i-1]) return "NO";
    }
    return result;
}

 let str3="found7, time: study; Yduts; emit, 7Dnuof";
console.log(solution(str3));