Krononberg

프로그래머스) 문자열 다루기 기본 c++ 본문

개발 로그/알고리즘

프로그래머스) 문자열 다루기 기본 c++

k._. 2021. 9. 3. 09:26

핵심 : 주어진 조건을 꼼꼼히 확인하는가.

 

문제 제목은 문자열 다루기 이지만, 개인적으로 이 문제는 주어진 조건을 sensitive 하게 생각하는지를 묻는 문제이다. string size가 4또는6인지에 대한 조건은 생각안하고 넘어가기 쉽기 때문이다.

 

isdigit, isnumber 쓰려면

#include <string>
#include <vector>
#include <cctype>

using namespace std;

bool solution(string s) {
    bool answer = false;
    if(s.size()==4 || s.size()==6) answer = true;
    for(int i =0; i<s.size(); i++){
        if(!isdigit(s[i])) answer = false;
    }
    return answer;
}