[BE] ์ด์ฃผ์ ๐ฅ ์ค๋์ ์ง๊ฟ์?#7
[BE] ์ด์ฃผ์ ๐ฅ ์ค๋์ ์ง๊ฟ์?#7leejuae wants to merge 2 commits intoLeets-Official:mainfrom
Conversation
taeseokyang
left a comment
There was a problem hiding this comment.
์๊ณ ํ์ จ์ต๋๋ค!!
ํ ์คํธ ํ๋ฆฐํธ๋ ๊ตฌํ ํด์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค!
| public void run() { | ||
| Scanner sc = new Scanner(System.in); | ||
| String members = sc.nextLine(); | ||
| int ret = 1; |
There was a problem hiding this comment.
๋ฑ ๋ณด๊ณ ์๋ฏธ๋ฅผ ์ ์ ์๋๋ก ๋ณ์๋ช ์ ์ ์ด์ฃผ์๋ฉด ์ข์๊ฑฐ ๊ฐ์ต๋๋ค!
| } | ||
|
|
||
| // ๋ฌธ์์ด๋ก๋ ๋ฉค๋ฒ๋ค์ ๋ฆฌ์คํธ๋ก ๋ถ๋ฆฌํ๋ ํจ์์ ๋๋ค. | ||
| public List<String> parseMembers(String members) { |
There was a problem hiding this comment.
return Arrays.asList(members.split(","));
์ ์ ๊ฐ์ด ์์ฑํ์๋ฉด ์ฝ๊ฒ ๋ถ๋ฆฌ ํ ์ ์์ต๋๋ค!
ChatGPT๋ฅผ ์ด์ฉํ์ฌ ์ฝ๋๋ฅผ ๋ถ์ฌ ๋ฃ๊ณ "๋ ์ข์ ๋ฐฉ๋ฒ์ด ์์๊น? ๋ฆฌํฉํ ๋งํด์ค' ์ ๊ฐ์ด ์ง๋ฌธํ์๋ฉด ์ข์ ํผ๋๋ฐฑ์ ๋ฐ์ ์ ์์ต๋๋ค!
There was a problem hiding this comment.
๊ทธ๋ ๊ฒ๋ ์งํผํฐ๋ฅผ ์ฌ์ฉํด๋ณผ ์ ์๊ฒ ๋ค์!! ์ฐธ๊ณ ํด๋ณด๊ฒ ์ต๋๋ค ใ ใ
| printResult(generateRandomGroups(memArray, maximumGroupSize)); | ||
|
|
||
| System.out.print("๋ค์ ๊ตฌ์ฑํ์๊ฒ ์ต๋๊น? (y or n): "); | ||
| String re = sc.nextLine(); |
There was a problem hiding this comment.
์ฝ๊ฒ ์ดํด ํ ์ ์๋ ๋ณ์๋ช ๋ถํ๋๋ฆฝ๋๋ค!
| } | ||
|
|
||
| // ๋ค์ ์ถ์ฒจ์ ์งํํ๋ ํจ์์ ๋๋ค. | ||
| public int reGeneration(String re) { |
There was a problem hiding this comment.
ํจ์๋ช ์ด ํจ์์ ๊ธฐ๋ฅ์ ์ ์ค๋ช ํด์ฃผ์ง ์๋๊ฒ ๊ฐ์ต๋๋ค!
getRetryDecision() ๊ฐ์๊ฑด ์ด๋จ๊น์?
'๋ค์ ์ถ์ฒจํ ์ง ๋ง์ง ์
๋ ฅ ๋ฐ๋ ํจ์ ์ด๋ฆ ๋ญ๋ผ๊ณ ํ ๊น?' ๋ผ๊ณ GPT์๊ฒ ๋ฌผ์ด๋ณธ ๊ฒฐ๊ณผ์
๋๋ค!
ay-eonii
left a comment
There was a problem hiding this comment.
์ฒซ ๋ฏธ์ ๊ณ ์ํ์ จ์ด์!
๋ฏธ์ ์์์ ๋งค์ฐ ์ ์ฌํ๊ฒ ๊ตฌํํด์ฃผ์ จ๋ค์๐
| int memberCount = memberNumber(memArray); | ||
| // ์ด๋ฆ ๊ฐ์๋ณด๋ค ์ง ์๊ฐ ๋ ๋ง์ผ๋ฉด ์์ธ๋ฐ์ | ||
| int maximumGroupSize = Integer.parseInt(sc.nextLine()); | ||
| checkDataValidity(memberCount, maximumGroupSize); |
There was a problem hiding this comment.
ํ๋์ ๋ฉ์๋์ ์ ์ ํ๊ฒ ์ฑ ์์ ๋ถ๋ฆฌํ๋ค์ ๐
|
|
||
| while (ret == 1){ | ||
| // ๋๋ค ์ง๊ถ ์ถ์ฒ | ||
| printResult(generateRandomGroups(memArray, maximumGroupSize)); |
There was a problem hiding this comment.
ํต์ฌ ๋ก์ง์ด ์จ์ด์์ด์~ ๐ถโ๐ซ๏ธ
| 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())))); |
There was a problem hiding this comment.
๋ค๋ฅธ ์ฌ๋์ด ์ฝ๊ฒ ์ดํดํ ์ ์๋๋ก inline์ผ๋ก ์ฌ์ฉํ ๋ก์ง์ ์ง์ญ๋ณ์๋ฅผ ์ฌ์ฉํด ๋ถ๋ฆฌํด๋ณด๋ ๊ฑด ์ด๋จ๊น์?
| 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(" ]"); | ||
| } |
There was a problem hiding this comment.
StringJoiner ๋๋ String.join()์ ๋ํด ์์๋ณด๋ฉด ๋์์ด ๋ ๊ฒ ๊ฐ์์ ๐
|
|
||
| // ๋ค์ ์ถ์ฒจ์ ์งํํ๋ ํจ์์ ๋๋ค. | ||
| public int reGeneration(String re) { | ||
| if(Objects.equals(re, "n")) { |
There was a problem hiding this comment.
String์ equals๊ฐ ์๋๋ผ Objects์ equals๋ฅผ ์ฌ์ฉํ ์ด์ ๊ฐ ๊ถ๊ธํด์!
There was a problem hiding this comment.
ํด๋น๋ถ๋ถ ์ ๊ฐ String ํด๋์ค์ ๋ํ ์ดํด๋๊ฐ ๋ถ์กฑํด์ ๊ทธ๋ฌ๋๊ฑฐ ๊ฐ์์!! String.equals(re, "n")์ด ๋ง๋ ๋ฌธ๋ฒ์ด๋ผ ์๊ฐํ๋๋ฐ ๋ค์ ์ฐพ์๋ณด๋ re.equals("n")๋ก ์ฒ๋ฆฌ๋ฅผ ํ์ด์ผ ํ๋ค์..ใ ใ ๊ทธ๋ฅ ๋์ด๊ฐ๋ป ํ๋ ๋ถ๋ถ์ธ๋ฐ ๋๋ถ์ ๋ค์ ์ง๊ณ ๋์ด๊ฐ ์ ์์์ด์!
There was a problem hiding this comment.
Object.equals()๋ ์ฃผ์๊ฐ์ ๋น๊ตํ๋๋ฐ, String.equals()๋ ๋ฌธ์ ํ๋ํ๋๋ฅผ ๋น๊ตํด์! ๊ฐ์ "n" ์ด๋๋ผ๋ Object.equals()๋ฅผ ์ฌ์ฉํ๋ฉด false๊ฐ ๋์ฌ ์ ์๋๊ฑฐ์ฃ ! ์ด๋ฐ ๋ฌธ์ ๊ฐ ์์ด ๋ฌธ์์ด์ ๋น๊ตํ ๋๋ String.equals()๋ฅผ ์ฌ์ฉํ๋๊ฒ ์ข์์!
์ถ๊ฐ์ ์ผ๋ก, re.equals("n")์ ๊ฒฝ์ฐ re๊ฐ null์ด๋ผ๋ฉด ๋ฌธ์ ๊ฐ ์์ ๊ฑฐ ๊ฐ์๋ฐ์๐ค
| return 0; | ||
| } else if (Objects.equals(re, "y")) { | ||
| return 1; |
There was a problem hiding this comment.
0 ๋๋ 1์ ๋ฐํํ๋ ๋ฏํ๋ฐ boolean์ ์ฌ์ฉํ์ง ์์ ์ด์ ๊ฐ ์์๊น์?
There was a problem hiding this comment.
๊ทธ๋ ๊ฒ ์ฒ๋ฆฌํ๋๊ฒ๋ ์ข์๊ฑฐ ๊ฐ๋ค์! bool ๋ฆฌํด๋ณด๋จ 0,1 ๋ฆฌํด์ด ์ข ๋ ์ต์ํด์ ์ด๋ ๊ฒ ์ฒ๋ฆฌํ๋๊ฑฐ ๊ฐ์์ ใ ใ
| // ๋์ ํจ์์ ๋๋ค. | ||
| public void run() { | ||
| Scanner input = new Scanner(System.in); // Scanner ํด๋์ค ์์ฑ | ||
| int ret = 1; // loop ๋๋ฆฌ๊ธฐ ์ํ ๋ณ์ ์ค์ |
There was a problem hiding this comment.
boolean ํ์
์ผ๋ก ๋ณ์๋ฅผ ์ ์ธํด์ฃผ๋ฉด ์ข์์ ๊ฒ ๊ฐ์์!
| while(st.hasMoreTokens()) | ||
| memArray.add(st.nextToken()); | ||
|
|
||
| return memArray; |
There was a problem hiding this comment.
StringTokenizer๋ ์ข์ง๋ง, split()๋ฉ์๋๋ ํ์ฌ ๋ก์ง์์ ์๋นํ ๊ด์ฐฎ์ ๋ณด์
๋๋ค!
|
|
||
| // ๋ฉค๋ฒ ๋ฌธ์์ด์ ์์ด๊ฐ ์๋์ง ๊ฒ์ฌํฉ๋๋ค. ์์ด๊ฐ ์๋ค๋ฉด ์์ธ ์ถ๋ ฅ | ||
| public void checkHasNoEnglish(String members) { | ||
| if (!members.matches("[๊ฐ-ํฃ,]+")) { |
There was a problem hiding this comment.
๋ฉ์๋๋ช ๊ณผ ๋ฉ์๋๊ฐ ํ๋ ํ์๊ฐ ์ผ์นํ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค!
๋ฏธ์ ์คํ ๊ฒฐ๊ณผ
๊ธฐ๋ฅ ๋ช ์ธ์
๊ธฐ๋ฅ
์ฐธ์ฌ์์ ์ด๋ฆ์ ์ ๋ ฅํ ์, ํ์ด ๋๋ค๋ฐฐ์ ๋จ.
๋ค์ ๋๋ค์ผ๋ก ์ ๋ ฅ์ ๋ฐ๊ธฐ ์ํ๋ฉด, y๋ฅผ ์ ๋ ฅํ๋ฉด ์ธ์์ด ์ฌ๋ฐฐ์ด๋จ.
n์ ์ ๋ ฅ ์์ ํ๋ก๊ทธ๋จ ์ข ๋ฃ
ERROR SATUS
์ฐธ์ฌ์ ์ด๋ฆ ์ ๋ ฅ ์ ์์ด๊ฐ ์ ๋ ฅ๋๋ฉด ์ค๋ฅ ๋ฐ์
์ต๋ ์ง์๊ฐ ์ ๋ ฅ๋ ์ธ์๋ณด๋ค ๋ง์ ์ ์ค๋ฅ๋ฐ์
y/n ์ด์ธ์ ๋ฌธ์๊ฐ ์ ๋ ฅ ์ ์ค๋ฅ ๋ฐ์