Skip to content

Commit e638740

Browse files
committed
[Iterations] swea-1289
1 parent 03eb7f4 commit e638740

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
| # || Problem | Note |
1515
| :-: | :-: | :------------------------------------------------------- | :--- |
1616
| 01 | | [Codility-Lesson1 BinaryGap](./src/Iterations/BinaryGap) | |
17+
| 02 | | [SWEA-1289 원재의 메모리 복구하기](./src/Iterations/swea1289) | |
1718

1819
## Simulation
1920

src/Iterations/swea1289/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## [SW Expert Academy - 1289] 원재의 메모리 복구하기
2+
3+
![image](https://user-images.githubusercontent.com/22045163/106429941-7ed66900-64ae-11eb-89ca-e161485f6530.png)
4+
5+
![image](https://user-images.githubusercontent.com/22045163/106429801-48005300-64ae-11eb-82d9-1076ad145137.png)

src/Iterations/swea1289/Solution.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package Iterations.swea1289;
2+
3+
import java.io.*;
4+
5+
public class Solution {
6+
7+
static int T;
8+
static String input;
9+
static StringBuilder sb = new StringBuilder();
10+
11+
public static void main(String[] args) throws Exception {
12+
System.setIn(new FileInputStream("src/Iterations/swea1289/input.txt"));
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
15+
T = Integer.parseInt(br.readLine());
16+
17+
for (int t = 1; t <= T; t++) {
18+
sb.append("#").append(t).append(" ");
19+
input = br.readLine();
20+
int cnt = 0;
21+
char cursor = '0';
22+
for (int i = 0; i < input.length(); i++) {
23+
if (input.charAt(i) == cursor) continue;
24+
cursor = (cursor == '0') ? '1' : '0';
25+
cnt ++;
26+
}
27+
sb.append(cnt).append("\n");
28+
}
29+
30+
System.out.println(sb.toString());
31+
}
32+
}

src/Iterations/swea1289/input.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
0011
3+
100

0 commit comments

Comments
 (0)