-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMadScientist.java
More file actions
28 lines (23 loc) · 842 Bytes
/
MadScientist.java
File metadata and controls
28 lines (23 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.io.*;
import java.util.*;
class MadScientist {
public static void main (String[] args) throws IOException{
BufferedReader f = new BufferedReader(new FileReader("breedflip.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("breedflip.out")));
int n = Integer.parseInt(f.readLine());
char[] a = f.readLine().toCharArray();
char[] b = f.readLine().toCharArray();
boolean mismatch = false;
int numFlip = 0;
for (int i = 0; i < n; i++) {
if (a[i] != b[i]) {//if a and b are not the same
if (mismatch == false) { //if first time mismatched
mismatch = true;
numFlip++;
}
}else {mismatch = false;}
}
out.println(numFlip);
f.close(); out.close();
}
}