Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions problems/SWEA/p1289/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package p1289;

import java.util.Scanner;

public class Solution {
static Scanner scanner;

public static void main(String[] args) {
scanner = new Scanner(System.in);

int testCount = scanner.nextInt();
scanner.nextLine();

for (int testCase = 1; testCase <= testCount; testCase++) {
Solution solution = new Solution(testCase);
solution.run();
}

scanner.close();
}

int testCase;
int answer;
String goalMem;

public Solution(int testCase) {
this.testCase = testCase;
}

public void run() {
input();
solve();
print();
}

private void print() {
System.out.printf("#%d %d\n", testCase, answer);
}

private void solve() {
answer = 0;

// 앞에서 부터 목표 값이랑 비교하면서 덮어씌운다
// 이미 목표 값이랑 동일하면 설정안하고 그냥 다음으로 커서를 넘긴다.

final int memSize = goalMem.length();
char filled = '0';

for (int cursor = 0; cursor < memSize; cursor++) {
if (goalMem.charAt(cursor) != filled) {
answer++;
filled = filled == '0' ? '1' : '0';
}
}
}

private void input() {
goalMem = scanner.nextLine().trim();
}
}
32 changes: 32 additions & 0 deletions problems/SWEA/p1289/Solution2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package p1289;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Solution2 {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringBuilder output = new StringBuilder();

int testCount = Integer.parseInt(reader.readLine().trim());

for (int testCase = 1; testCase <= testCount; testCase++) {
int answer = 0;

String goalMem = reader.readLine().trim();
final int memSize = goalMem.length();
char filled = '0';

for (int cursor = 0; cursor < memSize; cursor++) {
if (goalMem.charAt(cursor) != filled) {
answer++;
filled = filled == '0' ? '1' : '0';
}
}

output.append(String.format("#%d %d\n", testCase, answer));
}

System.out.print(output.toString());
}
}