[HackerRank] - Beautiful Binary String - c++

ha·2022년 6월 13일
0

HackerRank

목록 보기
1/1

0100101010에서 겹치는 경우 제외한 010갯수 세는 방법(find 여러번 사용방법)

int beautifulBinaryString(string b) {
    string pattern = "010";
    int answer=0;
    size_t pos = b.find(pattern);
    if(pos!=string::npos) answer++;
    while(1)
    {
        pos = b.find(pattern, pos+ 3);
        if(pos == string::npos) break;
        else {cout<<pos<<' ';answer++;}
    }
    return answer;
}

0개의 댓글