[알고리즘] 문제풀이 연습
[프로그래머스] p와 y찾기 : level 1
ddgoori
2019. 11. 5. 13:11
#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++;
}
if(s[i] == 'y' || s[i] == 'Y') {
Ycnt++;
}
}
if(Pcnt == 0 && Ycnt == 0) {
answer = true;
} if(Pcnt == Ycnt) answer = true;
else answer = false;
return answer;
}
level 1은 어느정도 풀 수 있으니 이제 level 2를 도전해봐야겠다.