구현문제임
int <-> char 간의 암시적 형변환과 아스키 코드를 알고있는지 물어보는 문제인거같다.
#include <iostream>
#include <vector>
using namespace std;
#define MAX 151
string arr[MAX];
int Count[26];
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> arr[i];
for (int i = 1; i <= n; ++i) Count[arr[i][0] - 'a']++;
int c = 0;
for (int i = 0; i < 26; ++i)
{
if (Count[i] >= 5) cout << char(97 + i);
else ++c;
}
if (c == 26) cout << "PREDAJA";
return 0;
}
나는 이렇게 그냥 바로 char(97 + i);를 형변환해서 출력했는데 아래 풀이의 코드가 더 깔끔하고
c++의 암시적 형변환을 잘 활용한 코드같다.
좀더 배우도록 하자..
#include <iostream>
#include <vector>
using namespace std;
#define MAX 151
string arr[MAX];
int Count[26];
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
{
string s;
cin >> s;
Count[s[0] - 'a']++;
};
string ret;
for (int i = 0; i < 26; ++i) if (Count[i] >= 5) ret += (i + 'a');
if (ret.size()) cout << ret;
else cout << "PREDAJA";
cout << 'a' + 1;
return 0;
}