Skip to content

Commit 7da4af4

Browse files
committed
[Simulation] baekjoon-1244
1 parent e638740 commit 7da4af4

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

โ€ŽREADME.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
| 02 | | [Baekjoon-14891 ํ†ฑ๋‹ˆ๋ฐ”ํ€ด](./src/Simulation/P14891) | |
2525
| 03 | | [Baekjoon-15662 ํ†ฑ๋‹ˆ๋ฐ”ํ€ด (2)](./src/Simulation/P15662) | |
2626
| 04 | | [Baekjoon-12100 2048 (Easy)](./src/Simulation/P12100) | ์‚ผ์„ฑ SW ์—ญ๋Ÿ‰ ํ…Œ์ŠคํŠธ ๊ธฐ์ถœ |
27+
| 05 | | [Baekjoon-1244 ์Šค์œ„์น˜ ์ผœ๊ณ  ๋„๊ธฐ](./src/Simulation/P1244) | |
2728

2829
## String
2930

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

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package Simulation.P1244;
2+
3+
import java.io.*;
4+
import java.util.*;
5+
6+
public class Main {
7+
8+
static int N, S;
9+
static int[] switches;
10+
11+
public static void main(String[] args) throws Exception {
12+
System.setIn(new FileInputStream("src/Simulation/P1244/input.txt"));
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
15+
N = Integer.parseInt(br.readLine());
16+
switches = new int[N+1];
17+
18+
StringTokenizer st = new StringTokenizer(br.readLine());
19+
for (int i = 1; i <= N; i++) switches[i] = Integer.parseInt(st.nextToken());
20+
21+
S = Integer.parseInt(br.readLine());
22+
while (S-- > 0) {
23+
st = new StringTokenizer(br.readLine());
24+
int gender = Integer.parseInt(st.nextToken());
25+
int num = Integer.parseInt(st.nextToken());
26+
27+
if (gender == 1) {
28+
for (int i = num; i <= N; i += num) changeSwitch(i);
29+
} else if (gender == 2) {
30+
changeSwitch(num);
31+
int i = 1;
32+
while (0 < num-i && num+i <= N) {
33+
if (switches[num-i] == switches[num+i]) {
34+
changeSwitch(num-i);
35+
changeSwitch(num+i);
36+
i++;
37+
} else break;
38+
}
39+
}
40+
}
41+
42+
for (int i = 1; i <= N; i++) {
43+
System.out.print(switches[i] + " ");
44+
if (i % 20 == 0) System.out.println();
45+
}
46+
}
47+
48+
static void changeSwitch(int i) {
49+
switches[i] = switches[i] == 0 ? 1 : 0;
50+
}
51+
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## [baekjoon-1244] ์Šค์œ„์น˜ ์ผœ๊ณ  ๋„๊ธฐ
2+
3+
![image](https://user-images.githubusercontent.com/22045163/106439518-1e015d80-64bb-11eb-9f89-d91f1f8ed942.png)
4+
![image](https://user-images.githubusercontent.com/22045163/106439564-2e193d00-64bb-11eb-8edf-a7cb1803fd51.png)

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

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
8
2+
0 1 0 1 0 0 0 1
3+
2
4+
1 3
5+
2 3
6+
7+
//output
8+
1 0 0 0 1 1 0 1

0 commit comments

Comments
ย (0)