-
Notifications
You must be signed in to change notification settings - Fork 1
[권혁준-12주차 알고리즘 스터디] #60
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
Open
oncsr
wants to merge
7
commits into
main
Choose a base branch
from
khj20006/week-12
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7b57fcb
[BOJ-7682] 틱택토.md
oncsr ec910c4
[BOJ-1405] 미친 로봇.md
oncsr d986f96
[BOJ-3079] 입국심사.md
oncsr 8c63689
[BOJ-21278] 호석이 두 마리 치킨.md
oncsr 08787c7
[BOJ-2629] 양팔저울.md
oncsr 2e213e1
[BOJ-1327] 소트 게임.md
oncsr 2158d06
[BOJ-11049] 행렬 곱셈 순서.md
oncsr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| ```java | ||
|
|
||
| import java.util.*; | ||
| import java.io.*; | ||
|
|
||
| class Main { | ||
|
|
||
| // IO field | ||
| static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | ||
| static StringTokenizer st = new StringTokenizer(""); | ||
|
|
||
| static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} | ||
| static String nextToken() throws Exception { | ||
| while(!st.hasMoreTokens()) nextLine(); | ||
| return st.nextToken(); | ||
| } | ||
| static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } | ||
| static long nextLong() throws Exception { return Long.parseLong(nextToken()); } | ||
| static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } | ||
| static void bwEnd() throws Exception {bw.flush();bw.close();} | ||
|
|
||
| // Additional field | ||
|
|
||
| static char[][] T; | ||
| static String temp; | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
|
|
||
| for(temp = br.readLine();!temp.equals("end");temp = br.readLine()) { | ||
|
|
||
| ready(); | ||
| solve(); | ||
| } | ||
|
|
||
| bwEnd(); | ||
|
|
||
| } | ||
|
|
||
| static void ready() throws Exception{ | ||
|
|
||
| T = new char[3][3]; | ||
| for(int i=0;i<9;i++) T[i/3][i%3] = temp.charAt(i); | ||
|
|
||
| } | ||
|
|
||
| static void solve() throws Exception{ | ||
|
|
||
| // X의 개수 - O의 개수 확인 | ||
| int xCount = 0, oCount = 0; | ||
| for(int i=0;i<3;i++) for(int j=0;j<3;j++) { | ||
| xCount += T[i][j] == 'X' ? 1 : 0; | ||
| oCount += T[i][j] == 'O' ? 1 : 0; | ||
| } | ||
| if(xCount - oCount < 0 || xCount - oCount > 1) { | ||
| bw.write("invalid\n"); | ||
| return; | ||
| } | ||
|
|
||
| // 대각선 승리 | ||
| int xDiagWin = 0, oDiagWin = 0; | ||
| if(T[0][0] == 'X' && T[1][1] == 'X' && T[2][2] == 'X') xDiagWin++; | ||
| if(T[0][0] == 'O' && T[1][1] == 'O' && T[2][2] == 'O') oDiagWin++; | ||
| if(T[0][2] == 'X' && T[1][1] == 'X' && T[2][0] == 'X') xDiagWin++; | ||
| if(T[0][2] == 'O' && T[1][1] == 'O' && T[2][0] == 'O') oDiagWin++; | ||
| if(xDiagWin > 0) { | ||
| if(xCount == oCount) { | ||
| bw.write("invalid\n"); | ||
| return; | ||
| } | ||
| bw.write("valid\n"); | ||
| return; | ||
| } | ||
| else if(oDiagWin > 0) { | ||
| if(xCount > oCount) { | ||
| bw.write("invalid\n"); | ||
| return; | ||
| } | ||
| bw.write("valid\n"); | ||
| return; | ||
| } | ||
|
|
||
| // 성공 패턴의 개수 | ||
| int xWin = 0, oWin = 0; | ||
| for(int i=0;i<3;i++) { | ||
| int res = 0; | ||
| for(int j=0;j<3;j++) res += T[i][j] == 'X' ? 1 : 0; | ||
| if(res == 3) xWin++; | ||
| res = 0; | ||
| for(int j=0;j<3;j++) res += T[i][j] == 'O' ? 1 : 0; | ||
| if(res == 3) oWin++; | ||
| } | ||
| for(int j=0;j<3;j++) { | ||
| int res = 0; | ||
| for(int i=0;i<3;i++) res += T[i][j] == 'X' ? 1 : 0; | ||
| if(res == 3) xWin++; | ||
| res = 0; | ||
| for(int i=0;i<3;i++) res += T[i][j] == 'O' ? 1 : 0; | ||
| if(res == 3) oWin++; | ||
| } | ||
| if(xWin + oWin == 0) { | ||
| if(xCount + oCount != 9) { | ||
| bw.write("invalid\n"); | ||
| return; | ||
| } | ||
| bw.write("valid\n"); | ||
| return; | ||
| } | ||
| if(xWin>0 && oWin>0) { | ||
| bw.write("invalid\n"); | ||
| return; | ||
| } | ||
|
|
||
| if(xWin > 0) { | ||
| if(xCount == oCount) { | ||
| bw.write("invalid\n"); | ||
| return; | ||
| } | ||
| bw.write("valid\n"); | ||
| return; | ||
| } | ||
| else { | ||
| if(xCount > oCount) { | ||
| bw.write("invalid\n"); | ||
| return; | ||
| } | ||
| bw.write("valid\n"); | ||
| return; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| ``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
이런 case work 문제들 풀 때에는 풀기 전에 명확하게 case 정리를 해놓고 구현하는 게 좋은 것 같더라구요 ,,
읽어주셔서 감사합니다 수고 많으셨어요 !