Problem Solving/프로그래머스
문자열 내 p와 y의 개수
높은곳에영광
2022. 1. 16. 23:18
#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;
}