[백준/C++] 11091 - 알파벳 전부 쓰기

orangesnail·2025년 8월 11일

백준

목록 보기
137/169

https://www.acmicpc.net/problem/11091


구현하기

<cctype> 내의 isalpha() 함수를 이용하면 어떤 문자가 알파벳인지 아닌지 판별이 가능하다. 알파벳이라면 1, 아니라면 0을 리턴한다. 또한 tolower() 함수를 이용하면 문자를 소문자로 변경할 수 있다.

이번 문제에서도 직전 문제와 마찬가지로 아스키 코드를 이용해서 입력받은 문자열의 각 문자가 알파벳 내에 존재하는지 검사하고, 존재 여부를 배열에 저장해둔다.


전체 코드

#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main() {
    int n;
    cin >> n;
    cin.ignore();

    for (int i = 0; i < n; i++) {
        string sen;
        getline(cin, sen);

        bool abc[26] = {false};

        for (char c : sen) {
            if (isalpha(c)) {
                char lowC = tolower(c);
                abc[lowC - 'a'] = true;
            }
        }

        bool pan = true;
        for (int j = 0; j < 26; j++) {
            if (!abc[j]) {
                pan = false;
                break;
            }
        }

        if (pan) cout << "pangram" << endl;
        else {
            cout << "missing ";
            for (int k = 0; k < 26; k++) {
                if (!abc[k]) cout << char('a' + k);
            }
            cout << endl;
        }
    }
    return 0;
}
profile
초보입니다. 피드백 환영합니다 😗

0개의 댓글