
소스코드
#include <iostream>
#include <string>
using namespace std;
int N;
int alphabet[26];
string s = "abcdefghijklmnopqrstuvwxyz";
int main(void) {
	cin >> N;
	for (int i = 0; i < N; i++) {
		string input;
		cin >> input;
		alphabet[input[0] - 'a']++;
	}
	bool predaja = true;
	for (int i = 0; i < 26; i++) {
		if (alphabet[i] >= 5) {
			cout << s[i];
			predaja = false;
		}
	}
	if (predaja) cout << "PREDAJA";
}
1. 이름의 첫 글자를 인덱스로 배열 채우기 - 'a' 인덱스 = 0, 'z' 인덱스 = 25
2. 5개 이상인 알파벳은 출력해주고 만약 5개 이상인 알파벳이 없으면(predaja 값이 바뀌지 않음) "PREDAJA" 출력
'개인 공부 > 코딩테스트' 카테고리의 다른 글
| [C++, Python][프로그래머스] 완주하지 못한 선수 :: seoftware (0) | 2020.08.09 | 
|---|---|
| [C++][프로그래머스] 가장 큰 수 :: seoftware (0) | 2020.04.25 | 
| [C++][백준] 14888번 연산자 끼워넣기 :: seoftware (0) | 2020.04.23 | 
| [C++][백준] 7568번 덩치 :: seoftware (0) | 2020.04.22 | 
| [C++][백준] 14501번 퇴사 :: seoftware (0) | 2020.04.22 | 
 
										
									 
										
									
댓글