-
Notifications
You must be signed in to change notification settings - Fork 14
[BE] ์ด์ฃผ์ ๐ฅ ์ค๋์ ์ง๊ฟ์? #7
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
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,38 +1,121 @@ | ||
| package leets.leets_mate; | ||
|
|
||
| import java.util.*; | ||
| import java.io.*; | ||
|
|
||
| public class LeetsMateApplication { | ||
|
|
||
| // ๋์ ํจ์์ ๋๋ค. | ||
| public void run() { | ||
| Scanner input = new Scanner(System.in); // Scanner ํด๋์ค ์์ฑ | ||
| int ret = 1; // loop ๋๋ฆฌ๊ธฐ ์ํ ๋ณ์ ์ค์ | ||
|
|
||
| // ๋ฉค๋ฒ ์ด๋ฆ ์ ๋ ฅ | ||
| System.out.println("๋ฉค๋ฒ์ ์ด๋ฆ์ ์ ๋ ฅํด ์ฃผ์ธ์. (, ๋ก ๊ตฌ๋ถ)"); | ||
| String members = input.nextLine(); | ||
|
|
||
| // ์์ด ์๋์ง ํ์ธ | ||
| checkHasNoEnglish(members); | ||
|
|
||
| // ๋ฆฌ์คํธ๋ก ๋ฉค๋ฒ ๋ถ๋ฆฌ | ||
| List<String> memArray = parseMembers(members); | ||
|
|
||
| // ๋ฉค๋ฒ ๋ช ์ ํ์ธ | ||
| int memberCount = memberNumber(memArray); | ||
|
|
||
| // ์ด๋ฆ ๊ฐ์๋ณด๋ค ์ง ์๊ฐ ๋ ๋ง์ผ๋ฉด ์์ธ๋ฐ์ | ||
| System.out.println("\n"+"์ต๋ ์ง ์๋ฅผ ์ ๋ ฅํด ์ฃผ์ธ์."); | ||
| int maximumGroupSize = Integer.parseInt(input.nextLine()); | ||
| checkDataValidity(memberCount, 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. ํ๋์ ๋ฉ์๋์ ์ ์ ํ๊ฒ ์ฑ ์์ ๋ถ๋ฆฌํ๋ค์ ๐ |
||
|
|
||
|
|
||
| // ๋ค์ ์์ฑ์ ์งํํ ์ง ๋ฌป๋ ํจ์ | ||
|
|
||
| while (ret == 1){ | ||
| // ๋๋ค ์ง๊ถ ์ถ์ฒ | ||
| printResult(generateRandomGroups(memArray, 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. ํต์ฌ ๋ก์ง์ด ์จ์ด์์ด์~ ๐ถโ๐ซ๏ธ |
||
|
|
||
| System.out.print("\n"+"๋ค์ ๊ตฌ์ฑํ์๊ฒ ์ต๋๊น? (y or n): "); | ||
| String re = input.nextLine(); | ||
| System.out.println("--------------------------------"); | ||
| ret = reGeneration(re); | ||
|
|
||
| if(ret != 1) break; | ||
| } | ||
|
|
||
| input.close(); | ||
| } | ||
|
|
||
| // ๋ฌธ์์ด๋ก๋ ๋ฉค๋ฒ๋ค์ ๋ฆฌ์คํธ๋ก ๋ถ๋ฆฌํ๋ ํจ์์ ๋๋ค. | ||
| public List<String> parseMembers(String members) { | ||
|
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.
ChatGPT๋ฅผ ์ด์ฉํ์ฌ ์ฝ๋๋ฅผ ๋ถ์ฌ ๋ฃ๊ณ "๋ ์ข์ ๋ฐฉ๋ฒ์ด ์์๊น? ๋ฆฌํฉํ ๋งํด์ค' ์ ๊ฐ์ด ์ง๋ฌธํ์๋ฉด ์ข์ ํผ๋๋ฐฑ์ ๋ฐ์ ์ ์์ต๋๋ค!
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<>(); | ||
| // ์ ์ฅํ ๋ฆฌ์คํธ | ||
| List<String> memArray = new ArrayList<String>(); | ||
|
|
||
| // ,๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ฌธ์์ด ๋ถ๋ฆฌ | ||
| StringTokenizer st = new StringTokenizer(members, ","); | ||
|
|
||
| // ๋ฌธ์์ด ๋ฆฌ์คํธ์ ์ ์ฅ | ||
| while(st.hasMoreTokens()) | ||
| memArray.add(st.nextToken()); | ||
|
|
||
| return memArray; | ||
|
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.
|
||
| } | ||
|
|
||
| // ์ด ๋ฉค๋ฒ์๋ฅผ ๋ฐํํฉ๋๋ค. | ||
| public int memberNumber(List<String> members) { | ||
| return 0; | ||
| return members.size(); | ||
| } | ||
|
|
||
| // ๋ฉค๋ฒ ๋ฌธ์์ด์ ์์ด๊ฐ ์๋์ง ๊ฒ์ฌํฉ๋๋ค. ์์ด๊ฐ ์๋ค๋ฉด ์์ธ ์ถ๋ ฅ | ||
| public void checkHasNoEnglish(String members) { | ||
| if (!members.matches("[๊ฐ-ํฃ,]+")) { | ||
|
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. ๋ฉ์๋๋ช ๊ณผ ๋ฉ์๋๊ฐ ํ๋ ํ์๊ฐ ์ผ์นํ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
||
| throw new IllegalArgumentException("[ERROR] ์ด๋ฆ์ ํ๊ธ๋ก ์ ๋ ฅํด์ผ ํฉ๋๋ค"); | ||
| } | ||
| } | ||
|
|
||
| // ๋ฉค๋ฒ์์ ์ต๋ ์ง์ ๋ฐ์ดํฐ๊ฐ ์ ํจํ์ง ๊ฒ์ฌํ๋ ํจ์์ ๋๋ค. ์ ํจํ์ง ์๋ค๋ฉด ์์ธ ์ถ๋ ฅ | ||
| public void checkDataValidity(int memberCount, int maximumGroupSize) { | ||
| if (memberCount < maximumGroupSize) { | ||
| throw new IllegalArgumentException("[ERROR] ์ต๋ ์ง ์๋ ์ด๋ฆ์ ๊ฐฏ์๋ณด๋ค ํด ์ ์์ต๋๋ค"); | ||
| } | ||
| } | ||
|
|
||
| // ๋๋ค ์ง๊ฟ ์ถ์ฒจํ๋ ํจ์ ์ ๋๋ค. | ||
| public List<List<String>> generateRandomGroups(List<String> memberList, int maximumGroupSize) { | ||
| return new ArrayList<>(); | ||
| Collections.shuffle(memberList); | ||
| List<List<String>> groups = new ArrayList<>(); | ||
| for (int i = 0; i < memberList.size(); i += maximumGroupSize) { | ||
| groups.add(new ArrayList<>(memberList.subList(i, Math.min(i + maximumGroupSize, memberList.size())))); | ||
|
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. ๋ค๋ฅธ ์ฌ๋์ด ์ฝ๊ฒ ์ดํดํ ์ ์๋๋ก inline์ผ๋ก ์ฌ์ฉํ ๋ก์ง์ ์ง์ญ๋ณ์๋ฅผ ์ฌ์ฉํด ๋ถ๋ฆฌํด๋ณด๋ ๊ฑด ์ด๋จ๊น์? |
||
| } | ||
| return groups; | ||
| } | ||
|
|
||
| // ๊ฒฐ๊ณผ๋ฅผ ํ๋ฆฐํธ ํ๋ ํจ์์ ๋๋ค. | ||
| public void printResult(List<List<String>> result) { | ||
| System.out.println("\n"+"์ค๋์ ์ง ์ถ์ฒ ๊ฒฐ๊ณผ์ ๋๋ค."); | ||
| for (List<String> group : result) { | ||
| System.out.print("[ "); | ||
| for (int i = 0; i < group.size(); i++) { | ||
| System.out.print(group.get(i)); | ||
| if (i < group.size() - 1) { | ||
| System.out.print(" | "); | ||
| } | ||
| } | ||
| System.out.println(" ]"); | ||
| } | ||
|
Comment on lines
+96
to
+105
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.
|
||
| System.out.println("\n"+"์ถ์ฒ์ ์๋ฃํ์ต๋๋ค."); | ||
| } | ||
|
|
||
| // ๋ค์ ์ถ์ฒจ์ ์งํํ๋ ํจ์์ ๋๋ค. | ||
| public int reGeneration(String re) { | ||
|
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. ํจ์๋ช ์ด ํจ์์ ๊ธฐ๋ฅ์ ์ ์ค๋ช ํด์ฃผ์ง ์๋๊ฒ ๊ฐ์ต๋๋ค! getRetryDecision() ๊ฐ์๊ฑด ์ด๋จ๊น์? |
||
| if(re.equals("n")) { | ||
| System.out.println("์๋ฆฌ๋ฅผ ์ด๋ํด ์๋ก์๊ฒ ์ธ์ฌํด์ฃผ์ธ์."); | ||
| return 0; | ||
| } else if (re.equals("y")) { | ||
| return 1; | ||
| } else { | ||
| throw new IllegalArgumentException("[ERROR] y๋๋ n์ ์ ๋ ฅํด์ผ ํฉ๋๋ค"); | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
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ํ์ ์ผ๋ก ๋ณ์๋ฅผ ์ ์ธํด์ฃผ๋ฉด ์ข์์ ๊ฒ ๊ฐ์์!