본문 바로가기

Algorithm/Programers - C++

[프로그래머스]문자열 다루기 기본/isdigit

문제

풀이

#include <string>
#include <vector>
#include <cctype>
using namespace std;

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

 

isdigit()

- <cctype> 헤더에 있다.

- 매개변수로 들어온 char 타입이 10진수 숫자로 변경이 가능하면 0이 아닌 숫자(true), 아니면 0(false)을 반환하는 함수.

 

 


https://blockdmask.tistory.com/362

 

[C언어/C++] isdigit (숫자를 판단하는 함수)

안녕하십니다. BlockDMask 입니다. 오늘은 C언어 및 C++에서 문자를 다룰때 이걸 숫자인지 판단해야하는 경우가 있지 않았나요? 그럴때 사용하라고 C/C++에서 이미 만들어 놓은 함수가 있습니다. 바로

blockdmask.tistory.com