코딩테스트/프로그래머스
[레벨1] 문자열 내 p와 y의 개수
marmelo12
2021. 9. 5. 13:52
반응형
#include <string>
#include <iostream>
using namespace std;
bool solution(string s)
{
bool answer = true;
int len = s.size();
int pCount = 0, yCount = 0;
for(int i = 0; i < len; ++i)
{
if(s[i] == 'p' || s[i] == 'P')
++pCount;
else if(s[i] == 'y' || s[i] == 'Y')
++yCount;
}
if(pCount != yCount)
answer = false;
return answer;
}
다른 사람의 코드를 보면 다 비슷하게 풀었더라.
반응형