Java/Java 알고리즘

백준 20650번 Do You Know Your ABCs? JAVA 구현해보기

kimc 2022. 6. 2. 10:53

```

백준 20650번 Do You Know Your ABCs? JAVA 구현해보기

```

이번 글을 통해 배워갈 내용

  1. 백준 20650번 풀이

https://www.acmicpc.net/problem/20650

 

20650번: Do You Know Your ABCs?

Farmer John's cows have been holding a daily online gathering on the "mooZ" video meeting platform. For fun, they have invented a simple number game to play during the meeting to keep themselves entertained. Elsie has three positive integers $A$, $B$, and

www.acmicpc.net

 

백준 20650번 Do You Know Your ABCs? 는

 

난이도 브론즈 등급의 문제로서

 

A, B, C, A+B, B+C, A+C, A+B+C 가 순서 없이 주어질 때

A <=B <=C 일 경우

ABC를 공백을 가지고 출력해주면 되는 문제입니다.

 


30분 정도 위에 링크를 방문하셔서 풀어보시고

안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.


가장 작은 두 수가

A, B이고

두 번째로 큰 수가 B+C 이기 때문에

수들을 정렬하고

해당되는 수의 위치를 이용해서

ABC를 구하고 출력했습니다

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) throws IOException {
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final String input01 = br.readLine();
        System.out.print(solution(input01));
    }

    private static String solution(String input01) {
        final int LIMIT = 3;
        final List<Integer> coordinateList = Arrays.stream(input01.split(" "))
                .map(Integer::parseInt)
                .sorted()
                .collect(Collectors.toList());

        List<Integer> abcList = new ArrayList<>();
        abcList.add(coordinateList.get(0));
        abcList.add(coordinateList.get(1));
        abcList.add(coordinateList.get(coordinateList.size() - 2) - coordinateList.get(1));

        StringBuilder sb = new StringBuilder();
        IntStream.range(0, LIMIT).forEach(idx ->
                sb.append(abcList.get(idx)).append(" ")
        );

        sb.setLength(sb.length() - 1);
        return sb.toString();
    }
}

 

읽어주셔서 감사합니다

 

무엇인가 얻어가셨기를 바라며

 

오늘도 즐거운 코딩 하시길 바랍니다 ~ :)

 


 

728x90