코드
#include <iostream>
#include <string>
using namespace std;
void answer(const string* _str)
{
string test = *_str;
int countB = 0; // B의 개수
int countS = 0; // S의 개수
int countA = 0; // A의 개수
for (int i = 0; i < test.size(); i++) {
if (test[i] == 'B') { // B의 개수 카운트
++countB;
}
else if (test[i] == 'S') { // S의 개수 카운트
++countS;
}
else { // A의 개수 카운트
++countA;
}
}
if (countB == countS && countS == countA) // 3개의 수가 같으면
{
cout << "SCU";
}
else
{
int maxnum = max(max(countB, countS), countA); // 가장 큰 값 찾기
// 가장 큰값하고 같은 경우 문자 출력
if (maxnum == countB) {
cout << 'B';
}
if(maxnum == countS) {
cout << 'S';
}
if (maxnum == countA) {
cout << 'A';
}
}
}
int main()
{
int n;
cin >> n;
string str;
cin >> str;
answer(&str);
}
'C++ > 백준 C++' 카테고리의 다른 글
[C/C++] 백준 30007번 라면 공식 (0) | 2023.12.21 |
---|---|
[C/C++] 백준 1075번 나누기 (2) | 2023.12.20 |
[C/C++] 백준 30979번 유치원생 파댕이 돌보기 (0) | 2023.12.18 |
[C/C++] 백준 12904번 A와 B (2) | 2023.12.17 |
[C/C++] 백준 4134번 다음 소수 - 참고 (0) | 2023.12.16 |