Bomb Kirby Running
Cat Life - GT-K
12916번 문자열 내 p와 y의 개수

2023. 3. 27. 09:04Programmers

코딩테스트 연습 - Level 1 - 문자열 내 p와 y의 개수

https://programmers.co.kr/learn/courses/30/lessons/12916

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

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

    return answer;
}