Solution1)
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
int A = 0, B = 0, C = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
A = Integer.parseInt(br.readLine());
B = Integer.parseInt(br.readLine());
C = Integer.parseInt(br.readLine());
int result = A * B * C;
ArrayList<Integer> nums = new ArrayList<>(); //result가 몇자리 수일지 알 수 없으므로 크기가 유동적인 리스트 사용.
while(result > 0){
nums.add(result % 10);
result /= 10;
}
int [] numsArr = nums.stream().mapToInt(Integer::intValue).toArray();
//mapToInt(class::method) -> class에 있는 method를 이용해 값들을 하나씩 변환
//mapToInt(i -> function) -> 값들을 i에 받아와서 function으로 변환. ex) function = i+1
int [] check = new int[10]; //초기화 없이 선언시 배열 값 0으로 초기화
for(int i : numsArr)
check[i]++;
for(int k : check)
System.out.println(k);
}
}
Solution2)
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
int A = 0, B = 0, C = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
A = Integer.parseInt(br.readLine());
B = Integer.parseInt(br.readLine());
C = Integer.parseInt(br.readLine());
int result = A * B * C;
int [] check = new int[10]; //초기화 없이 선언시 배열 값 0으로 초기화
while(result > 0){
check[result % 10]++;
result /= 10;
}
for(int k : check)
System.out.println(k);
}
}
메모리
: Sol1 > Sol2
시간
: Sol2(124ms) = Sol1(124ms)
'BOJ' 카테고리의 다른 글
백준 2747번 피보나치 수 [C언어] (0) | 2022.08.15 |
---|---|
백준 2863번 이게 분수? [C언어] (0) | 2022.08.13 |
백준 1018번 체스판 다시 칠하기 [C언어] (0) | 2022.08.10 |
백준 1977번 완전제곱수 [C언어] (0) | 2022.08.08 |
백준 1436번 영화감독 숌 [C언어] (0) | 2022.08.07 |