백준/문제

6750번: Rotating letters

스몰스테핑 2024. 9. 10. 11:21

문제 출처 : https://www.acmicpc.net/problem/6750

 

언어 : Kotlin

 

문제 설명 :

An artist wants to construct a sign whose letters will rotate freely in the breeze. In order to do this, she must only use letters that are not changed by rotation of 180 degrees: I, O, S, H, Z, X, and N.

Write a program that reads a word and determines whether the word can be used on the sign.

 

입력 :

The input will consist of one word, all in uppercase letters, with no spaces. The maximum length of the word will be 30 letters, and the word will have at least one letter in it.

 

출력 :

Output YES if the input word can be used on the sign; otherwise, output NO

 

제한 사항 :

  • 시간 제한 : 1초
  • 메모리 제한 : 128MB

 

입출력 예 :

입력 출력
SHINS YES

 

풀이 : 

import java.io.BufferedWriter
import java.io.OutputStreamWriter

fun main() = with(System.`in`.bufferedReader()) {
    val bw = BufferedWriter(OutputStreamWriter(System.out))

    var result = true
    val pattern = arrayOf('I', 'O', 'S', 'H', 'Z', 'X', 'N')
    readLine().let { str ->
        val cnt = str.filter { c ->
            pattern.any { it == c }
        }.length

        if (str.length != cnt) result = false
    }

    bw.write(if (result) "YES" else "NO")
    bw.flush()
    bw.close()
}