알고리즘
[알고리즘] c++ cpp 문자열 내 p와 y의 개수
keel_im
2020. 10. 21. 10:24
반응형
포인트
1. 문자열을 순회 해서 p와 y의 개수를 세면 된다. (string 을 순회를 할때는 char 자료형이다. )
🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다.
#include <string>
#include <iostream>
using namespace std;
bool solution(string s) {
int p = 0;
int y = 0;
for (auto element : s) {
if (element == 'p' || element == 'P') p++;
if (element == 'y' || element == 'Y') y++;
}
return (p == y) ? true : false;
}
반응형