C++/백준 C++

[C/C++] 백준 30957번 빅데이터 vs 정보보호 vs 인공지능

CE : 하랑 2023. 12. 19. 09:52

 

 

 

 

 

코드

#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);
}