개인 공부/코딩테스트
[C++][백준] 1159번 농구 경기
seowit
2020. 4. 24. 15:45
소스코드
#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" 출력