```
백준 25053번 Organizing SWERC JAVA 구현해보기
```

이번 글을 통해 배워갈 내용
- 백준 25053번 풀이
https://www.acmicpc.net/problem/25053
25053번: Organizing SWERC
Explanation of sample 1. In the first test case, Gianni has received only $3$ problems, with difficulties $3$, $4$, $7$ which are not sufficient to create a problem set (for example because there is not a problem with difficulty $1$). In the second test ca
www.acmicpc.net
백준 25053번 Organizing SWERC은
난이도 브론즈 등급의 문제로서
t 개의 테스트 케이스가 주어지고
각 테스트 케이스별로
문제의 수 n 이 주어진 다음
n개의 문제별로
1부터 10 사이의 b 점수와
1부터 10 사이의 d 난이도가 주어질 때
각 테스트 케이스별로
난이도 d 가 1에서 10 사이의 수를 포함하지 않으면 "MOREPROBLEMS"을 출력하고
포함한다면 각 난이도별로 가장 점수가 높은 값의 합을 구해주면 됩니다.
30분 정도 위에 링크를 방문하셔서 풀어보시고
안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.
입력되는 모든 값들을 problem data transfer object (problemDto)에 넣어주고
중복되는 값들을 insert method 시에 distinctive 하고 가장 큰 값을 DTO에 넣어줌으로 해결하였고
findTotalBeauty 메서드를 사용해서 10개의 1부터 10까지의 difficulty가 있으면 beauty score에 합을 출력하고
없다면 MOREPROBLEMS을 출력하였습니다.
위의 내용을 테스트 케이스만큼 반복하고 결과값들을 스트링 빌더에 넣어서 마지막에 한번 출력해주었습니다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
final int testCase = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < testCase; i++) {
ProblemDto problemDto = new ProblemDto();
final int problems = Integer.parseInt(br.readLine());
for (int j = 0; j < problems; j++) {
String[] inputArr = br.readLine().split(" ");
problemDto.insert(Integer.parseInt(inputArr[0]), Integer.parseInt(inputArr[1]));
}
sb.append(problemDto.findTotalBeauty()).append("\n");
}
sb.setLength(sb.length() - 1);
System.out.print(sb);
}
private static class ProblemDto {
private final int[] beautyScoreArr;
private final boolean[] isDifficultyArr;
public ProblemDto() {
beautyScoreArr = new int[11];
isDifficultyArr = new boolean[11];
isDifficultyArr[0] = true;
}
public void insert(int beautyScore, int difficulty) {
if (!isDifficultyArr[difficulty]) {
isDifficultyArr[difficulty] = true;
}
if (beautyScoreArr[difficulty] < beautyScore) {
beautyScoreArr[difficulty] = beautyScore;
}
}
public String findTotalBeauty() {
String retVal = "MOREPROBLEMS";
if (hasAllDifficulty()) {
retVal = String.valueOf(Arrays.stream(beautyScoreArr).sum());
}
return retVal;
}
private boolean hasAllDifficulty() {
boolean hasAllDifficulty = true;
for (boolean b : isDifficultyArr) {
if (!b) {
hasAllDifficulty = false;
break;
}
}
return hasAllDifficulty;
}
}
}
//codemasterkimc.tistory.com [김씨의 코딩 스토리]
읽어주셔서 감사합니다
무엇인가 얻어가셨기를 바라며
오늘도 즐거운 코딩 하시길 바랍니다 ~ :)
'Java > Java 알고리즘' 카테고리의 다른 글
| 백준 25088번 Punched Cards JAVA 구현해보기 (0) | 2022.05.28 |
|---|---|
| 백준 25205번 경로당펑크 2077 JAVA 구현해보기 (0) | 2022.05.28 |
| 백준 25183번 인생은 한 방 JAVA 구현해보기 (0) | 2022.05.28 |
| 백준 25165번 영리한 아리의 포탈 타기 JAVA 구현해보기 (0) | 2022.05.28 |
| 백준 25191번 치킨댄스를 추는 곰곰이를 본 임스 JAVA 구현해보기 (0) | 2022.05.25 |