본문 바로가기

백준/C++

[Baekjoon/C++] 6750번 - Rotating letters

[백준] Baekjoon Online Judge

문제로 이동

 

문제

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

 


풀이

#include <iostream>
using namespace std;

char letter[7] = { 'I', 'O', 'S', 'H', 'Z', 'X', 'N' };

bool canUse(char c);

bool canUse(char c) {
    for (int i = 0; i < 7; i++) {
        if (c == letter[i]) return true;
    }

    return false;
}

int main() {
    string s;
    cin >> s;

    for (int i = 0; i < s.length(); i++) {
        if (!canUse(s[i])) {
            cout << "NO\n";
            return 0;
        }
    }

    cout << "YES\n";

    return 0;
}

 입력 받은 문자열의 문자를 모두 검사하여 하나라도 사용 가능한 문자가 아니라면 NO를, 사용 가능 문자로만 구성되어 있다면 YES를 출력하면 된다.