문자열 내 p와 y의 개수

magicdrill·2024년 3월 4일
0

문자열 내 p와 y의 개수

#include <string>
#include <iostream>
using namespace std;

bool solution(string s)
{
    bool answer = true;
    int i, length = s.length();
    int p_count = 0, y_count = 0;
    // [실행] 버튼을 누르면 출력 값을 볼 수 있습니다.
    //cout << "Hello Cpp" << endl;
    for(i = 0; i < length; i++)
    {
        if(s[i] == 'p' || s[i] == 'P')
        {
            p_count++;
        }
        else if(s[i] == 'y' || s[i] == 'Y')
        {
            y_count++;
        }
        else
        {
            ;
        }
    }
    if(p_count == y_count)
    {
        answer = true;
    }
    else
    {
        answer = false;
    }

    return answer;
}

0개의 댓글