-
Notifications
You must be signed in to change notification settings - Fork 14
[BE] ์ด์ฃผ์ฐ ๐ฅ ์ค๋์ ์ง๊ฟ์? #18
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,41 +1,134 @@ | ||
| package leets.leets_mate; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.BufferedWriter; | ||
| import java.io.InputStreamReader; | ||
| import java.io.OutputStreamWriter; | ||
| import java.sql.SQLOutput; | ||
| import java.util.*; | ||
| import java.io.*; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class LeetsMateApplication { | ||
|
|
||
| // ๋์ ํจ์์ ๋๋ค. | ||
| public void run() { | ||
| public void run() throws Exception { | ||
|
|
||
| System.out.println("[Leets ์ค๋์ ์ง์๊ฒ]๋ฅผ ์์ํฉ๋๋ค.\n"); | ||
|
|
||
| //๋ฉค๋ฒ ๋ฌธ์์ด ์ ๋ ฅ ๋ฐ๊ธฐ ๋ฐ ํ์ฑ | ||
| System.out.println("๋ฉค๋ฒ์ ์ด๋ฆ์ ์ ๋ ฅํด ์ฃผ์ธ์. (, ๋ก ๊ตฌ๋ถ)"); | ||
| Scanner sc = new Scanner(System.in); | ||
| String input = sc.nextLine(); | ||
| List<String> memberList = parseMembers(input); | ||
|
|
||
| //์ต๋ ์ง ์ ์ ๋ ฅ ๋ฐ๊ธฐ ๋ฐ ์ ํจ์ฑ ๊ฒ์ฌ | ||
| System.out.println("\n์ต๋ ์ง ์๋ฅผ ์ ๋ ฅํด ์ฃผ์ธ์."); | ||
| int maximumGroupSize = 0; | ||
| try{ | ||
| maximumGroupSize = Integer.parseInt(sc.nextLine()); | ||
| } | ||
| catch (Exception e){ | ||
| throw new Exception("[ERROR] ์ต๋ ์ง ์๋ ์ซ์์ฌ์ผํฉ๋๋ค"); | ||
| } | ||
| checkDataValidity(memberNumber(memberList), maximumGroupSize); | ||
|
|
||
| char re = '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. ์๋ฏธ๊ฐ ๋ช ํํ ๋ณ์๋ช ์ด๋ฉด ์ข์๊ฑฐ ๊ฐ์์! |
||
| while(re == 'y'){ | ||
| //๋๋ค ์ง ์์ฑ ๋ฐ ์ถ๋ ฅ | ||
| System.out.println("\n์ค๋์ ์ง ์ถ์ฒ ๊ฒฐ๊ณผ์ ๋๋ค."); | ||
| List<List<String>> result = generateRandomGroups(memberList, maximumGroupSize); | ||
| printResult(result); | ||
| System.out.println("\n์ถ์ฒ์ ์๋ฃํ์ต๋๋ค."); | ||
|
|
||
| //์ฌ๊ตฌ์ฑ | ||
| System.out.print("๋ค์ ๊ตฌ์ฑํ์๊ฒ ์ต๋๊น? (y or n): "); | ||
| re = sc.nextLine().charAt(0); | ||
| if (re != 'y' && re != 'n') { | ||
| throw new Exception("[ERROR]'y' ๋๋ 'n'์ ์ ๋ ฅํด์ฃผ์ธ์"); | ||
| } | ||
| if(re == 'y'){ | ||
| System.out.print("--------------------------------"); | ||
| } | ||
| } | ||
| System.out.println("์๋ฆฌ๋ฅผ ์ด๋ํด ์๋ก์๊ฒ ์ธ์ฌํด์ฃผ์ธ์."); | ||
|
|
||
| } | ||
|
|
||
| // ๋ฌธ์์ด๋ก๋ ๋ฉค๋ฒ๋ค์ ๋ฆฌ์คํธ๋ก ๋ถ๋ฆฌํ๋ ํจ์์ ๋๋ค. | ||
| public List<String> parseMembers(String members) { | ||
| return new ArrayList<>(); | ||
| public List<String> parseMembers(String members) throws Exception { | ||
| checkHasNoEnglish(members); | ||
| List<String> memberList = Arrays.asList(members.split(",")); | ||
| return memberList; | ||
| } | ||
|
|
||
| // ์ด ๋ฉค๋ฒ์๋ฅผ ๋ฐํํฉ๋๋ค. | ||
| public int memberNumber(List<String> members) { | ||
| return 0; | ||
| return members.size(); | ||
| } | ||
|
|
||
| // ๋ฉค๋ฒ ๋ฌธ์์ด์ ์์ด๊ฐ ์๋์ง ๊ฒ์ฌํฉ๋๋ค. ์์ด๊ฐ ์๋ค๋ฉด ์์ธ ์ถ๋ ฅ | ||
| public void checkHasNoEnglish(String members) { | ||
| public void checkHasNoEnglish(String members) throws Exception { | ||
| // ๋ฉค๋ฒ ๋ฌธ์์ด์ ํ๊ธ, ์ปด๋ง(,), ๊ณต๋ฐฑ๋ง ํ์ฉ | ||
| if(!Pattern.matches("^[ใฑ-ใ ๊ฐ-ํฃ,\\s]*$", members)){ | ||
| //์์ธ ๋ฐ์ | ||
| 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] ์ต๋ ์ง ์๋ ์ด๋ฆ์ ๊ฐฏ์๋ณด๋ค ํด ์ ์์ต๋๋ค\n"); | ||
| } | ||
| if(maximumGroupSize <= 0){ | ||
|
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. ์ ๋ ์ง ์๊ฐ 0์ด ๋ ์ ์๋ค๋ ์ ์ ๋์ณค์๋๋ฐ, ์์ธ ์ฒ๋ฆฌ๋ฅผ ์ ํ์ ๊ฒ ๊ฐ์ต๋๋ค. |
||
| throw new Exception("[ERROR] ์ต๋ ์ง ์๋ 1 ์ด์์ด์ด์ผ ํฉ๋๋ค\n"); | ||
|
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. ์ง ์ ์ ๋ ฅ๊ฐ์ด 0์ดํ์ธ๊ฑด ์๊ฐ ๋ชปํ๋๋ฐ ์์ธ ์ฒ๋ฆฌ ์์ฃผ ์ข์ต๋๋ค!! :) |
||
| } | ||
| } | ||
|
|
||
| // ๋๋ค ์ง๊ฟ ์ถ์ฒจํ๋ ํจ์ ์ ๋๋ค. | ||
| public List<List<String>> generateRandomGroups(List<String> memberList, int maximumGroupSize) { | ||
| return new ArrayList<>(); | ||
|
|
||
| Collections.shuffle(memberList); | ||
|
|
||
| List<String> mate = new ArrayList<>(); | ||
| List<List<String>> result = new ArrayList<>(); | ||
|
|
||
| int memberCount = memberNumber(memberList); | ||
|
|
||
| for(int i = 0; i<memberCount; i++){ | ||
| mate.add(memberList.get(i)); | ||
|
|
||
| if(mate.size() == maximumGroupSize | ||
| || i == memberCount - 1){ | ||
| result.add(new ArrayList<>(mate)); | ||
| mate = new ArrayList<>(); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| // ๊ฒฐ๊ณผ๋ฅผ ํ๋ฆฐํธ ํ๋ ํจ์์ ๋๋ค. | ||
| public void printResult(List<List<String>> result) { | ||
| for (List<String> mate : result) { | ||
|
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("[ "); | ||
| Iterator<String> iterator = mate.iterator(); | ||
|
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. Iterator๋ฅผ ์ด์ฉํด์ ์ง์ ๋ง๋์ ์ ์ด ์ธ์๊น์์ต๋๋ค!
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. Iterator ๋ฐฉ์๋ ์ข๋ค์! |
||
|
|
||
| while (iterator.hasNext()) { | ||
| String name = iterator.next(); | ||
| System.out.print(name); | ||
|
|
||
| if (iterator.hasNext()) { | ||
| System.out.print(" | "); | ||
| } | ||
| } | ||
|
|
||
| System.out.print(" ]\n"); | ||
| } | ||
| } | ||
|
|
||
| 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.
๋ฌด์จ ์ธํ์ธ์ง ์ ์ ์๋ ๋ณ์๋ช ์ด๋ฉด ์ข์๊ฑฐ ๊ฐ์์! ์ง๊ธ์ input? ๋ฌด์จ input์ด์ง? ํ๊ณ ๋ค๋ฅธ ์ฝ๋๋ฅผ ๋ด์ผํด์ ๊ฐ๋ ์ฑ์ด ๋จ์ด์ง๋๋ค!