코딩테스트/문제풀이
[220825] Level_ 1 문자열 내 p와 y의 개수
Honey Badger
2022. 8. 25. 20:32
https://school.programmers.co.kr/learn/courses/30/lessons/12916
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#include <string>
using namespace std;
bool solution(const string s)
{
bool answer = false;
int count = 0;
for (auto c : s)
{
if ('p' == c || 'P' == c) count++;
else if ('y' == c || 'Y' == c) count--;
else continue;
}
if (count == 0 && s.size() > 0) answer = true;
return answer;
}