728x90
반응형
다른 사람들의 코드도 나랑 비슷한 것 같아서 업로드는 하지 않았다. 걍 y,Y와 p,P의 개수를 세고 비교하면 됨.
#include <string>
#include <iostream>
using namespace std;
bool solution(string s)
{
bool answer = true;
int count_p = 0;
int count_y = 0;
for(int i = 0 ; i < s.size(); i++)
{
if(s[i] =='p' || s[i] == 'P')
{
count_p ++;
}
else if(s[i] == 'y' || s[i] == 'Y')
{
count_y ++;
}
}
// [실행] 버튼을 누르면 출력 값을 볼 수 있습니다.
if(count_p != count_y)
{
answer = false;
}
return answer;
}
728x90
반응형
'Computer Science > Coding Test' 카테고리의 다른 글
c++(cpp) 프로그래머스 - 코딩 테스트 : 두 정수 사이의 합 (0) | 2022.08.13 |
---|---|
c++(cpp) 프로그래머스 - 코딩 테스트 : 3진법 뒤집기 (0) | 2022.08.11 |
c++(cpp) 프로그래머스 - 코딩 테스트 : 문자열 내림차순으로 배치하기 (0) | 2022.08.11 |
c++(cpp) 프로그래머스 - 코딩 테스트 : 문자열 다루기 기본 (0) | 2022.08.11 |
c++(cpp) 프로그래머스 - 코딩 테스트 : 약수의 합 (0) | 2022.08.11 |
댓글