문제
제출답안
import java.util.*;
class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
String[] num = new String[input.length()];
int clapCount = 0;
for(int i=0; i<Integer.parseInt(input); i++){
String str = Integer.toString(i);
if(i < 10){ // 숫자가 한자리일 때
if(str.contains("3") || str.contains("6") || str.contains("9")) {
clapCount++;
}
}else{ // 숫자가 두자리 이상일 때
for(int j=0; j<str.length(); j++){
num[j] = Character.toString(Integer.toString(i).charAt(j)); // 각 자릿수의 숫자를 배열에 입력
}
for(int k=0; k<str.length(); k++) {
if(num[k].contains("3") || num[k].contains("6") || num[k].contains("9")) {
clapCount++;
continue; // 3,6,9 중에 중복되는 문자가 있는 숫자는 한번만 세기
}
}
}
}
System.out.println(clapCount);
}
}
출처