C++:: 프로그래머스 < 문자열 내 p와 y의 개수 >

jahlee·2023년 8월 9일
0

프로그래머스_Lv.1

목록 보기
70/75
post-thumbnail

p와 y 개수에 따른 결과를 리턴해주면 되는 문제이다. 간단하다.

#include <string>
using namespace std;

bool solution(string s) {
    int answer = 0;
    for (auto c : s) {
        if (tolower(c) == 'p') answer++;
        else if (tolower(c) == 'y') answer--;
    }
    return !answer;
}

0개의 댓글