Java/Java 알고리즘

백준 5063번 TGN JAVA 구현해보기

kimc 2022. 6. 4. 23:59

```

백준 5063번 TGN JAVA 구현해보기

```

이번 글을 통해 배워갈 내용

  1. 백준 5063번 TGN 풀이

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

 

5063번: TGN

첫째 줄에 테스트 케이스의 개수 N이 주어진다. 다음 N개의 줄에는 3개의 정수 r, e, c가 주어진다. r은 광고를 하지 않았을 때 수익, e는 광고를 했을 때의 수익, c는 광고 비용이다. (-106 ≤ r,e ≤ 106

www.acmicpc.net

 

백준 5063번 TGN은

 

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

 

테스트 케이스를 입력받고

테스트 케이스만큼

광고를 한 후 매출

광고를 안한후 매출

광고비가 주어질 때

 

광고를 하는게 이득이면

advertise

광고를 하는것과 안 하는 것이 상관없으면
does not matter

광고를 안 하는 게 이득이면
do not advertise

를 출력하면 되는 문제입니다.


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

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


입력을 받고

광고 후 매출과 광고를 안 한 매출 더하기 광고비를 비교해서 결과를 출력해주면 됩니다.

 

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;

public class Main {

    public static void main(String[] args) throws IOException {
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int testCase = Integer.parseInt(br.readLine());
        List<String> inputList = new ArrayList<>();
        for (int i = 0; i < testCase; i++) {
            inputList.add(br.readLine());
        }
        System.out.print(solution(inputList));
    }

    public static String solution(List<String> inputList) {
        StringBuilder sb = new StringBuilder();
        inputList.forEach(input -> {
            List<Integer> rec = Arrays.stream(input.split(" ")).map(Integer::parseInt).collect(Collectors.toList());
            final int revenueWithoutAd = rec.get(0);
            final int revenueWithAd = rec.get(1);
            final int adCost = rec.get(2);

            if (revenueWithAd > (revenueWithoutAd + adCost)) {
                sb.append("advertise");
            } else if (revenueWithAd < (revenueWithoutAd + adCost)) {
                sb.append("do not advertise");
            } else {
                sb.append("does not matter");
            }
            sb.append("\n");

        });

        if (sb.length() > 0) {
            sb.setLength(sb.length() - 1);
        }

        return sb.toString();
    }
}

// https://codemasterkimc.tistory.com

 

 

읽어주셔서 감사합니다

 

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

 

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

 


 

728x90