Problem Solving/백준 1일 1커밋

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

HWAN JJ 2022. 1. 16. 21:42

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

 

11091번: 알파벳 전부 쓰기

팬그램은 26개의 알파벳, a~z를 최소 한번씩 모두 사용한 문장을 말한다. 아마 가장 유명한 문장은 이것일 것이다. "The quick brown fox jumps over the lazy dog." 꿍은 다른 문장들중에 팬그램인 것은 없는지

www.acmicpc.net

신촌 알고리즘 캠프 초급반 2주차 가장 쉬운 문제.

 

문자열이 주이지고, 해당 문자열 내에 대소문자 구분 없이 모든 알파벳이 사용되었는지 확인하고 

모든 알파벳이 사용된 경우, pangram을, 아닌 경우 missing과 함께 사용되지 않은 알파벳들을 출력한다.

 

C/C++ 에서 char 형 변수를 아스키 코드로 치환해서 비교해서 간단히 해결했다. 

 

오늘 문제는 너무 쉬워서 간단히 코드만!

 

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>

using namespace std;

int a[26] = {0, };

int check(string s) {
	
	int cnt = 0;
	memset(a, 0, sizeof(a));

	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j < 26; j++) {
			if (j + 'a' == s[i] || j + 'A' == s[i]) {
				if (!a[j]) {
					a[j] = 1; cnt++;
				}
				break;
			}
		}
	}
	return (26 - cnt);
}


int main(void) {

	int n;
	scanf("%d", &n);
	getchar();

	for (int i = 0; i < n; i++) {
		string s;
		getline(cin, s);
		if (!check(s))
			printf("pangram\n");
		else {
			printf("missing ");
			for (int j = 0; j < 26; j++) {
				if (!a[j])
					printf("%c", 'a' + j);
			}
			printf("\n");
		}
	}

	return 0;
}