-
Notifications
You must be signed in to change notification settings - Fork 14
[BE] ํ์ฑ๋ฏผ ๐ฅ ์ค๋์ ์ง๊ฟ์? #12
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 all commits
b1869f6
4289636
831502d
370dde5
f8a9842
2b5a685
83a3a1f
c3ee1e0
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,37 +5,116 @@ | |||||
| public class LeetsMateApplication { | ||||||
|
|
||||||
| // ๋์ ํจ์์ ๋๋ค. | ||||||
| public void run() { | ||||||
| public void run() throws Exception { | ||||||
| Scanner sc = new Scanner(System.in); | ||||||
|
|
||||||
| System.out.println("[Leets ์ค๋์ ์ง์๊ฒ]๋ฅผ ์์ํฉ๋๋ค.\n"); | ||||||
|
|
||||||
| System.out.println("์ฐธ์์๋ค์ ์ด๋ฆ์ ์ ๋ ฅํด ์ฃผ์ธ์. (,๋ก ๊ตฌ๋ถ)"); | ||||||
| String members = sc.nextLine(); | ||||||
|
|
||||||
| checkHasNoEnglish(members); | ||||||
|
|
||||||
| System.out.println("\n์ต๋ ์ง ์๋ฅผ ์ ๋ ฅํด ์ฃผ์ธ์."); | ||||||
| int maximumGroupSize = sc.nextInt(); | ||||||
|
|
||||||
| List<String> memberList = parseMembers(members); | ||||||
|
|
||||||
| checkDataValidity(memberNumber(memberList), maximumGroupSize); | ||||||
|
|
||||||
| printResult(generateRandomGroups(memberList, maximumGroupSize)); | ||||||
|
|
||||||
| while (true) { | ||||||
|
Member
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. ์์์
Member
Author
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. ์ค ์ข์ ๋ฐฉ๋ฒ์ด๋ค์! |
||||||
| System.out.print("๋ค์ ๊ตฌ์ฑํ์๊ฒ ์ต๋๊น? (y or n): "); | ||||||
| String answer = sc.next(); | ||||||
|
|
||||||
| if (answer.equals("y")) { | ||||||
|
Member
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. ๋ง์ฝ answer์ด null ์ด๋ผ๋ฉด ์ด๋ค ๋ฌธ์ ๊ฐ ์์๊น์?
Member
Author
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. null์ผ ๊ฒฝ์ฐ ์ข
๋ฃ๋๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ค์,,
Member
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. y ๋๋ n ์ธ๊ฒฝ์ฐ ์์ธ์ฒ๋ฆฌ๋ ์ค์ํฉ๋๋ค๐
Suggested change
์ด๋ ๊ฒ ๋ณ๊ฒฝํด๋ NPE๊ฐ ๋ฐ์ํ ๊ฐ๋ฅ์ฑ์ด ์์๊น์?
Member
Author
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. euqals ๋ฉ์๋๋ nullableํ ๊ฐ์ฒด๋ฅผ ์ธ์๋ก ๋ฐ๊ธฐ ๋๋ฌธ์ NPE๊ฐ ๋ฐ์ํ์ง ์์ ๊ฒ ๊ฐ์๋ฐ ์ด๋ป๊ฒ ์๊ฐํ์๋์ง ๊ถ๊ธํฉ๋๋ค !
Member
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.
๋ต ๋ง์์!
Member
Author
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. ์ ํ ์๊ฐํด๋ณธ์ ์์๋๋ฐ ๊นจ๋ซ๊ณ ๊ฐ๋๋ค ! |
||||||
| printResult(generateRandomGroups(memberList, maximumGroupSize)); | ||||||
| } else { | ||||||
| System.out.println("์๋ฆฌ๋ฅผ ์ด๋ํด ์๋ก์๊ฒ ์ธ์ฌํด์ฃผ์ธ์."); | ||||||
| break; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // ๋ฌธ์์ด๋ก๋ ๋ฉค๋ฒ๋ค์ ๋ฆฌ์คํธ๋ก ๋ถ๋ฆฌํ๋ ํจ์์ ๋๋ค. | ||||||
| public List<String> parseMembers(String members) { | ||||||
| return new ArrayList<>(); | ||||||
| return Arrays.asList(members.split(",")); | ||||||
| } | ||||||
|
|
||||||
| // ์ด ๋ฉค๋ฒ์๋ฅผ ๋ฐํํฉ๋๋ค. | ||||||
| public int memberNumber(List<String> members) { | ||||||
| return 0; | ||||||
| return members.size(); | ||||||
| } | ||||||
|
|
||||||
| // ๋ฉค๋ฒ ๋ฌธ์์ด์ ์์ด๊ฐ ์๋์ง ๊ฒ์ฌํฉ๋๋ค. ์์ด๊ฐ ์๋ค๋ฉด ์์ธ ์ถ๋ ฅ | ||||||
| public void checkHasNoEnglish(String members) { | ||||||
| public void checkHasNoEnglish(String members) throws Exception { | ||||||
| if (members.matches(".*[a-zA-Z].*")) { | ||||||
| throw new Exception("[ERROR] ์ด๋ฆ์ ํ๊ธ๋ก ์ ๋ ฅํด์ผ ํฉ๋๋ค"); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // ๋ฉค๋ฒ์์ ์ต๋ ์ง์ ๋ฐ์ดํฐ๊ฐ ์ ํจํ์ง ๊ฒ์ฌํ๋ ํจ์์ ๋๋ค. ์ ํจํ์ง ์๋ค๋ฉด ์์ธ ์ถ๋ ฅ | ||||||
| public void checkDataValidity(int memberCount, int maximumGroupSize) { | ||||||
| public void checkDataValidity(int memberCount, int maximumGroupSize) throws Exception { | ||||||
| if (memberCount < maximumGroupSize) { | ||||||
| throw new Exception("[ERROR] ์ต๋ ์ง ์๋ ์ด๋ฆ์ ๊ฐฏ์๋ณด๋ค ํด ์ ์์ต๋๋ค"); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // ๋๋ค ์ง๊ฟ ์ถ์ฒจํ๋ ํจ์ ์ ๋๋ค. | ||||||
| public List<List<String>> generateRandomGroups(List<String> memberList, int maximumGroupSize) { | ||||||
|
Member
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. ์ด ํจ์ ์ฝ๋๋ฅผ GPT๋ฅผ ํตํด ๊ฐ์ ํ๋ฉด ๋จ์ ๋ฉค๋ฒ ๋ฐ๋ก ์ฒ๋ฆฌ ํ๊ธฐ ์ซ์ด์ ์๋์ ๊ฐ์ ๋ฐฉ๋ฒ์ ์๊ฐํด ๋ณด์์ต๋๋ค. ์๋ง ๋ ์ข์ ๋ฐฉ๋ฒ์ด ์์ ๊ฑฐ ๊ฐ์๋ฐ, ์ ๋ฐฉ๋ฒ ๊ณต์ ํด ๋๋ฆฝ๋๋ค!
Member
Author
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. ๋จ์์๋ ๋ฉค๋ฒ์ ์ต๋ ๊ทธ๋ฃน ์๋ฅผ ๋น๊ตํด์ฃผ๋ฉด ๋๋๊ตฐ์ ! |
||||||
| return new ArrayList<>(); | ||||||
| Collections.shuffle(memberList); | ||||||
|
|
||||||
| List<List<String>> result = new ArrayList<>(); | ||||||
|
|
||||||
| int memberCount = memberNumber(memberList); | ||||||
| int groupCount = memberCount / maximumGroupSize; | ||||||
| int remainingMembers = memberCount % maximumGroupSize; | ||||||
|
|
||||||
| int currentIndex = 0; | ||||||
| for (int i = 0; i < groupCount; i++) { | ||||||
| List<String> group = new ArrayList<>(); | ||||||
| for (int j = 0; j < maximumGroupSize; j++) { | ||||||
| group.add(memberList.get(currentIndex)); | ||||||
| currentIndex++; | ||||||
| } | ||||||
| result.add(group); | ||||||
| } | ||||||
|
|
||||||
| if (remainingMembers > 0) { | ||||||
| List<String> lastGroup = new ArrayList<>(); | ||||||
| for (int i = currentIndex; i < memberCount; i++) { | ||||||
| lastGroup.add(memberList.get(i)); | ||||||
| } | ||||||
| result.add(lastGroup); | ||||||
| } | ||||||
|
|
||||||
| return result; | ||||||
| } | ||||||
|
|
||||||
| // ๊ฒฐ๊ณผ๋ฅผ ํ๋ฆฐํธ ํ๋ ํจ์์ ๋๋ค. | ||||||
| public void printResult(List<List<String>> result) { | ||||||
| System.out.println("\n์ค๋์ ์ง ์ถ์ฒ ๊ฒฐ๊ณผ์ ๋๋ค."); | ||||||
|
|
||||||
| StringBuilder sb = new StringBuilder(); | ||||||
|
|
||||||
| for (List<String> row : result) { | ||||||
| sb.append("[ "); | ||||||
| for (int j = 0; j < row.size(); j++) { | ||||||
| sb.append(row.get(j)); | ||||||
|
|
||||||
| if (j < row.size() - 1) { | ||||||
| sb.append(" | "); | ||||||
| } | ||||||
| } | ||||||
| sb.append(" ]\n"); | ||||||
| } | ||||||
|
Comment on lines
+101
to
+111
Member
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. StringJoiner๋ฅผ ์์๋ณด๋ฉด ๋์์ด ๋ ๊ฒ ๊ฐ๋ค์ ๐
Member
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. ์ถ๊ฐ์ ์ผ๋ก,
Member
Author
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. StringJoiner์ ์ฒ์ ๋ค์ด๋ณด๋๋ฐ ํ๋ฒ ์์๋ณผ๊ฒ์ !
Member
Author
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. ํ๋์ฝ๋ฉํ๋ฉด ์ฝ๋๊ฐ ์ง์ ๋ถํด๋ณด์ด๋ ๊ฒ๋ ๋ฌธ์ ์ ์ด๋ผ ํ ์ ์์ ๊ฑฐ ๊ฐ์๋ฐ
Member
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.
์ด์์ฒด์ ๋ง๋ค ๊ฐํ๋ฌธ์๊ฐ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ์ํ๋ ๋๋ก ์ค๋ฐ๊ฟ์ด ๋์ง ์์ ๊ฐ๋ฅ์ฑ์ด ์์ด๋ณด์ฌ์!
Member
Author
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. ์ค์ค,, ์ด์์ฒด์ ์ ๋ํ ์๊ฐ์ ์ ํ ํด๋ณธ ์ ์๋๋ฐ,, ์ด๋ฐ ์ผ์ด ๋ฐ์ํ ์๋ ์๊ตฐ์,,! ์ฐธ๊ณ ํ๊ฒ ์ต๋๋ค! ๊ฐ์ฌํด์ ใ ใ |
||||||
|
|
||||||
| sb.append("\n์ถ์ฒ์ ์๋ฃํ์ต๋๋ค.\n"); | ||||||
| System.out.println(sb); | ||||||
| } | ||||||
|
|
||||||
| public static void main(String[] args) { | ||||||
| public static void main(String[] args) throws Exception { | ||||||
| LeetsMateApplication app = new LeetsMateApplication(); | ||||||
| app.run(); | ||||||
| } | ||||||
|
|
||||||
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.
์์ธ ์ฒ๋ฆฌ ๋์ boolean์ผ๋ก ์ค์ ํด์ ์ข ๋ฃ๋์ง ์๊ณ ์ฌ์ ๋ ฅ ๋ฐ์ ์ ์๊ฒ ํด์ผ๊ฒ ๋ค์ !
์์ธ๋ฅผ ๋์ง๋ ๊ฒ๋ง์ด ๋ฐฉ๋ฒ์ธ์ค ์์๋๋ฐ ์๋ ค์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค :)