안녕 세상아,

[프로그래머스/c++] LV1 문자열 내 p와 y의 개수 본문

프로그래머스

[프로그래머스/c++] LV1 문자열 내 p와 y의 개수

돈 많은 백수가 되고싶다 2024. 7. 29. 15:28

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

확실히 알고리즘이 안붙으니까 쉽긴하네ㅋㅋㅋ...빨리 1단계 많이 풀고 2단계로 넘어가서 눈물 흘려야지...ㅜ

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

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