250x250
반응형
Notice
Recent Posts
Recent Comments
Link
목록쉽다 (1)
N

문자열 비교를 하여 p와 y의 개수를 세는 문제..! for문을 이용하여 문자열을 비교한다. 단, 대소문자를 구별하지 않으니 if문에 대소문자를 모두 포함해야 한다..! #include #include using namespace std; bool solution(string s) { bool answer = true; int pCount = 0, yCount = 0; for(int i = 0; i < s.size(); i++) { if(s[i] == 'p' || s[i] == 'P') pCount++; else if(s[i] == 'y' || s[i] == 'Y') yCount++; } if(pCount == yCount) return true; else return false; }
프로그래머스 알고리즘/1단계
2020. 4. 23. 13:53