[java] 백준 단계별로 풀어보기 5단계 (1)알고리즘/백준2021. 6. 28. 22:59
Table of Contents
1단계 10818번 최소, 최대
import java.util.Scanner;
import java.util.Arrays;
class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
System.out.print(arr[0] + " " + arr[n - 1]);
}
}
2단계 2562번 최댓값
import java.util.Scanner;
class Main {
public static void main(String []args) {
Scanner sc = new Scanner(System.in);
int arr[] = new int[9];
int max =0, count=0;
for(int i=0; i<arr.length; i++){
arr[i] = sc.nextInt();
// 최댓값, 위치 구하기
if(max < arr[i]) {
max = arr[i];
count=i+1;
}
}
System.out.println(max);
System.out.println(count);
}
}
3단계 2577번 숫자의 개수
import java.util.Scanner;
// import java.util.Arrays;
class Main {
public static void main(String []args) {
Scanner sc = new Scanner(System.in);
int result = 1, mod=0;
// 0~9까지 체크하기 위해서 배열 생성
int[] arr = new int[10];
for(int i=0; i<3; i++) {
int n=sc.nextInt();
result = result * n;
}
while(result>0) {
// mod의 값이 중복, 0~9까지 원소의 개수를 알 수 있음
mod = result%10;
arr[mod]++;
result/=10;
}
for(int j : arr)
System.out.println(j);
}
}
3단계 문제... 1시간 고민한 것 같습니다.
'알고리즘 > 백준' 카테고리의 다른 글
[java] 백준 단계별로 풀어보기 6단계 (0) | 2021.06.30 |
---|---|
[java] 백준 단계별로 풀어보기 5단계 (2) (0) | 2021.06.29 |
[java] 백준 단계별로 풀어보기 4단계 (0) | 2021.06.25 |
[java] 백준 단계별로 풀어보기 3단계 (3) (0) | 2021.06.24 |
[java] 백준 단계별로 풀어보기 3단계 (2) (0) | 2021.06.23 |
@펄찌 :: Pearl's Story
펄의 일상이 궁금한 사람 요기~
즐거운 하루 되셨으면 좋겠습니다😊