Skip to content

Commit c36e236

Browse files
committed
[Simulation] jungol-1037
1 parent 59ad7f5 commit c36e236

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

โ€ŽREADME.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
| 15 | | [Baekjoon-10163 ์ƒ‰์ข…์ด](./src/Simulation/P10163) | |
4545
| 16 | | [Baekjoon-13300 ๋ฐฉ ๋ฐฐ์ •](./src/Simulation/P13300) | |
4646
| 17 | | [Baekjoon-2477 ์ฐธ์™ธ๋ฐญ](./src/Simulation/P2477) | |
47+
| 18 | | [JUNGOL-1037 ์˜ค๋ฅ˜๊ต์ •](./src/Simulation/jo1037) | |
4748

4849
## String
4950

โ€Žsrc/Simulation/jo1037/Main.java

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package Simulation.jo1037;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileInputStream;
5+
import java.io.InputStreamReader;
6+
import java.util.StringTokenizer;
7+
8+
public class Main {
9+
10+
static int N;
11+
static int[][] map;
12+
13+
public static void main(String[] args) throws Exception {
14+
System.setIn(new FileInputStream("src/Simulation/jo1037/input.txt"));
15+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
16+
StringTokenizer st;
17+
18+
N = Integer.parseInt(br.readLine());
19+
map = new int[N][N];
20+
21+
for (int i = 0; i < N; i++) {
22+
st = new StringTokenizer(br.readLine());
23+
for (int j = 0; j < N; j++) {
24+
map[i][j] = Integer.parseInt(st.nextToken());
25+
}
26+
}
27+
28+
if (isParity()) System.out.println("OK");
29+
else chageBit();
30+
31+
}
32+
33+
static void chageBit() {
34+
for (int i = 0; i < N; i++) {
35+
for (int j = 0; j < N; j++) {
36+
map[i][j] = 1 - map[i][j];
37+
if (isParity()) {
38+
System.out.println("Change bit (" + (i+1) + "," + (j+1) + ")");
39+
return;
40+
}
41+
map[i][j] = 1 - map[i][j];
42+
}
43+
}
44+
45+
System.out.println("Corrupt");
46+
}
47+
48+
static boolean isParity() {
49+
int rCnt = 0, cCnt = 0;
50+
for (int i = 0; i < N; i++) {
51+
for (int j = 0; j < N; j++) {
52+
rCnt += map[i][j];
53+
cCnt += map[j][i];
54+
}
55+
if (rCnt%2 != 0 || cCnt%2 != 0) return false;
56+
}
57+
58+
return true;
59+
}
60+
}

โ€Žsrc/Simulation/jo1037/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## [JUNGOL-1037] ์˜ค๋ฅ˜๊ต์ •
2+
3+
![image](https://user-images.githubusercontent.com/22045163/109013023-056d1780-76f6-11eb-8a23-d7968c6d2a8e.png)
4+
5+
![image](https://user-images.githubusercontent.com/22045163/109013099-187fe780-76f6-11eb-8a48-cc6ce41d762e.png)

โ€Žsrc/Simulation/jo1037/input.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
1 0 1 0
3+
0 0 1 0
4+
1 1 1 1
5+
0 1 0 1

0 commit comments

Comments
ย (0)