본문 바로가기

Problem Solving/프로그래머스

문자열 내 p와 y의 개수

#include <string>
#include <iostream>
using namespace std;
int count(string s, char c) {
    int num = 0;
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] < 96) s[i] += 32;
        if(s[i] == c) ++num;
    }
    return num;
}

bool solution(string s)
{
    int a; int b;
    a = count(s,'p');
    b = count(s,'y');
    
    if(a == 0 && b == 0) return true;
    else if(a == b) return true;
    else return false;
    //cout << "Hello Cpp" << endl;

}

'Problem Solving > 프로그래머스' 카테고리의 다른 글

구명보트  (0) 2022.01.16
실패율  (0) 2022.01.16
문자열 다루기 기본  (0) 2022.01.16
스킬트리  (0) 2022.01.16
나누어 떨어지는 숫자 배열  (0) 2022.01.16