Coding_Test 연습/Programmers

[프로그래머스] (C++) LV1 문자열 다루기 기본

Codetesing 2022. 4. 26. 10:13

isdigit 사용해서 반복문으로 풀었음.

#include <string>

using namespace std;

bool solution(string s) {
   
	if (s.size() != 4 && s.size() != 6)
		return false;

	for (int i = 0; i < s.size(); i++)
		if (!isdigit(s[i]))
			return false;

	return true;
}