Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- time complexity
- 코딩테스트
- 알고리즘
- Algorithm
- 프로그래머스 숫자의 표현 java
- 네트워크
- 백준 17425
- Arrays
- 프로그래머스 연속된 수의 합 java
- 백준 4375
- 백준 15661
- 백준 11723
- Math.ceil()
- Codility
- 프로그래머스 옹알이 java
- sort
- mysql
- 프로그래머스 도둑질 java
- 백준 14391
- 백준 18290
- java 내림
- Math.floor()
- 프로그래머스 네트워크 java
- 자바
- 백준 16935
- java 반올림
- 0으로 채우기
- java 올림
- 백준 16927
- java
Archives
- Today
- Total
취미처럼
[백준] 2309번 일곱 난쟁이 본문
https://www.acmicpc.net/problem/2309
2309번: 일곱 난쟁이
아홉 개의 줄에 걸쳐 난쟁이들의 키가 주어진다. 주어지는 키는 100을 넘지 않는 자연수이며, 아홉 난쟁이의 키는 모두 다르며, 가능한 정답이 여러 가지인 경우에는 아무거나 출력한다.
www.acmicpc.net
브루트토스 알고리즘 : 하나하나 모두 대입해서 찾는 방법
2개의 fake를 제외하고 합이 100이라면 정답
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
int[] arr = new int[9];
int sum = 0;
Scanner sc = new Scanner(System.in);
for(int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
sum += arr[i];
}
Arrays.sort(arr);
int fake1 = 0;
int fake2 = 0;
for(int i = 0; i < arr.length - 1; i++) {
for(int j = i + 1; j < arr.length; j++) {
if(sum - arr[i] - arr[j] == 100) {
fake1 = arr[i];
fake2 = arr[j];
}
}
}
for(int i = 0; i < arr.length; i++) {
if(arr[i] == fake1 || arr[i] == fake2) {
continue;
}
System.out.println(arr[i]);
}
}
}
'Algorithm > 백준' 카테고리의 다른 글
[백준] 1476번 날짜 계산 (0) | 2021.02.25 |
---|---|
[백준] 3085번 사탕 게임 (0) | 2021.02.25 |
[백준] 6588번 골드바흐의 추측 (0) | 2021.02.25 |
[백준] 1929번 소수 구하기 (0) | 2021.02.25 |
[백준] 1978번 소수 찾기 (0) | 2021.02.25 |
Comments