카테고리 없음

프로그래머스 문자열 내 p와 y의 개수

miffy짱 2022. 8. 8. 11:01
반응형

분명히

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

bool solution(string s)
{
    bool answer = true;
    int pcnt = 0;
    int ycnt = 0;
    
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'p' || s[i] == 'P')
            pcnt++;
        else if (s[i] == 'y' || s[i] == 'Y')
            ycnt++;
    }
    if (pcnt == ycnt) return true;
    else return false;
}

며칠전에 한거같은데...