Skip to content

Commit

Permalink
Create 191005-blackjack.md
Browse files Browse the repository at this point in the history
  • Loading branch information
super-fishz authored Oct 4, 2019
1 parent 63f9597 commit d4ff1bd
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions PS/191005-blackjack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## [black jack](https://www.acmicpc.net/problem/2798)

### Problem
주어진 카드 중 3장을 골라, 그 합이 m 가장 가까운 값을 리턴

### Solve
```java
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

int n = sc.nextInt();
int m = sc.nextInt();
int[] cards = new int[n];

for (int i = 0; i < n; i++) {
cards[i] = sc.nextInt();
}

int max = 0;
outline : for (int i = 0; i < n-2; i++) {
for (int j = i+1; j < n-1; j++) {
for (int k = j+1; k < n; k++) {

int sum = cards[i] + cards[j] + cards[k];
if(sum <= m) {
max = Math.max(max, sum);
}

if(max == m) {
break outline;
}
}
}
}

System.out.println(max);
}
}
```

0 comments on commit d4ff1bd

Please sign in to comment.