[백준] 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를 출력하면 된다.
'백준 > C++' 카테고리의 다른 글
[Baekjoon/C++] 14003번 - 가장 긴 증가하는 부분 수열 5 (0) | 2025.03.24 |
---|---|
[Baekjoon/C++] 12738번 - 가장 긴 증가하는 부분 수열 3 (0) | 2025.03.21 |
[Baekjoon/C++] 10824번 - 네 수 (0) | 2025.03.20 |
[Baekjoon/C++] 2150번 - Strongly Connected Component (0) | 2025.03.17 |
[Baekjoon/C++] 10886번 - 0 = not cute / 1 = cute (0) | 2025.03.13 |