-
Notifications
You must be signed in to change notification settings - Fork 0
Be/main/jongmlee java lv2 #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,20 @@ | ||
| package com.example.algorithmbot; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| Wchae wchae = new Wchae(); | ||
| List<Algorithm> algorithmList = List.of(new BFS(), new DFS(), new TwoPointer(), | ||
| new BinarySearch(), new DP()); | ||
|
|
||
| for (int i = 0; i < 20; i++) { | ||
| Algorithm first = algorithmList.get((int) (Math.random() * 5)); | ||
| Algorithm second = algorithmList.get((int) (Math.random() * 5)); | ||
| System.out.println(wchae.solveAlgorithm(first)); | ||
| System.out.println(wchae.solveAlgorithm(second)); | ||
| System.out.println(); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,34 @@ | ||
| package com.example.algorithmbot; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class Wchae { | ||
|
|
||
| private final Map<Algorithm, Integer> algorithmMap; | ||
|
|
||
| public Wchae() { | ||
| algorithmMap = new HashMap<>(); | ||
| } | ||
|
|
||
| public String solveAlgorithm(Algorithm algorithm) { | ||
| Integer solveCount = algorithmMap.getOrDefault(algorithm, 0); | ||
| // 풀어보지 못한 알고리즘인 경우 | ||
| if (algorithmMap.keySet() | ||
| .stream() | ||
| .filter(x -> x.isSolution(algorithm)) | ||
| .findAny().isEmpty()) { | ||
|
||
| algorithmMap.put(algorithm, 1); | ||
| return "스트레스 받네..."; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 상수로 빼주세여~(33줄 포함) |
||
| } | ||
| // 풀어본 알고리즘인 경우 | ||
| boolean isSolved = Math.random() * 10 > solveCount; | ||
| if (isSolved) { | ||
| if (solveCount < 10) { | ||
| algorithmMap.put(algorithm, solveCount + 1); | ||
| } | ||
| return algorithm.getSolution(); | ||
| } | ||
| return "스트레스 받네..."; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 코드만 봤을 땐, 출력 조건인
우주 : 알고리즘 / 알고리즘 이런 식으로 출력이 아니라
알고리즘
알고리즘
요렇게 출력 될 것 같은데 제가 맞게 이해한건가여??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
출력 형식도 안맞추고 냈네요.. 반성하겠습니다.. 바로 수정!!