728x90
level 1 : 문자열 다루기 기본
https://programmers.co.kr/learn/courses/30/lessons/12918?language=java
🎯 코드(C++)
#include <string>
#include <vector>
using namespace std;
bool solution(string s) {
bool answer = true;
if(s.size()!=4 && s.size()!=6){
return false;
}
for(int i=0; i<s.size(); i++){
if(!isdigit(s[i])){
return false;
}
}
return answer;
}
🎯 코드(JAVA)
class Solution {
public boolean solution(String s) {
boolean answer = true;
if(s.length() !=4 && s.length() != 6){
return false;
}
for(int i=0; i<s.length(); i++){
if(!Character.isDigit(s.charAt(i))){
return false;
}
}
return answer;
}
}
🎯 설명
string 길이
- C++ : s.size()
- JAVA : s.length()
string 특정위치
- C++ : s[i]
- JAVA : s.charAt[i]
숫자판별
- C++ : isdigit()
- JAVA : Character.isDigit()
728x90
'알고리즘 > 프로그래머스' 카테고리의 다른 글
프로그래머스(C++, JAVA) / level 1 : 내적 (0) | 2022.03.25 |
---|---|
프로그래머스(C++, JAVA) / level 1 : 음양 더하기 (0) | 2022.03.25 |
프로그래머스(C++, JAVA) / level 1 : 신고 결과 받기 (0) | 2022.03.25 |
프로그래머스(C++) / 프로그래머스 level 2 : 양궁대회 (0) | 2022.02.07 |
알고리즘(C++) / 프로그래머스 level 2 : 게임 맵 최단거리 (0) | 2022.02.04 |
댓글