관리 메뉴

Try

[Programmers/C++] 문자열 내 p와 y의 개수 본문

Algorithm/Programmers

[Programmers/C++] 문자열 내 p와 y의 개수

HAS3ONG 2019. 4. 12. 22:29

https://programmers.co.kr/learn/courses/30/lessons/12916

 

#include <string>
#include <iostream>
using namespace std;

bool solution(string s)
{
    bool answer = true;

    int y_cnt = 0;
    int p_cnt = 0;
    
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'p' || s[i] == 'P')
            p_cnt++;
        else if(s[i] == 'y' || s[i] == 'Y')
            y_cnt++;
        else
            continue;
    }
    
    if(p_cnt != y_cnt)
        answer = false;

    return answer;
}

 

 

간단한것도 있었네요..

Comments