-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreedflip.java
63 lines (51 loc) · 1.66 KB
/
breedflip.java
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
ID: siyonaona
LANG: JAVA
TASK: breedflip
*/
import java.io.*;
import java.util.StringTokenizer;
public class breedflip {
static void sameLetterRemove(char[] arr1, char[] arr2){ //replaces all same letters with 0
for(int i = 0; i < arr1.length; i++){
if(arr1[i] == arr2[i]){
arr2[i] = ' ';
}
}
}
static int checkNull(char[] arr){
int counter = 0;
for(int i = 0; i < arr.length - 1; i++){
if(arr[i] != ' ' && arr[i+1] == ' '){
counter += 1;
}
}
return counter;
}
static public void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new FileReader("breedflip.in")); //new FileReader("breedflip.in")
PrintWriter pw = new PrintWriter("breedflip.out");
StringTokenizer st = new StringTokenizer(bf.readLine());
int N = Integer.parseInt(st.nextToken());
char[] stringA = new char[N];
char[] stringB = new char[N];
StringTokenizer str = new StringTokenizer(bf.readLine()); //string A
String token1 = str.nextToken();
for(int j = 0; j < N; j++){
stringA[j] = token1.charAt(j);
}
StringTokenizer token = new StringTokenizer(bf.readLine());
String token2 = token.nextToken();
for(int j = 0; j < N; j++){
stringB[j] = token2.charAt(j);
}
sameLetterRemove(stringA, stringB);
if(stringB[N-1] != ' '){
pw.println(checkNull(stringB) + 1);
} else {
pw.println(checkNull(stringB));
}
pw.close();
bf.close();
}
}