-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBovineGenomics.java
More file actions
60 lines (59 loc) · 1.66 KB
/
BovineGenomics.java
File metadata and controls
60 lines (59 loc) · 1.66 KB
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
import java.io.*;
import java.util.*;
public class BovineGenomics {
static HashMap<String, int[]> diff = new HashMap<String, int[]>();
static String[] genes = new String[] {"A", "T", "G", "C"};
static char[][] genomes;
public static void main(String[] args) throws IOException
{
//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedReader br = new BufferedReader(new FileReader("cownomics.in"));
String key;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
for (int k = 0; k < 4; k++)
{
key = genes[i] + genes[j] + genes[k];
diff.put(key, new int[] {0, 0});
}
String[] temp = br.readLine().split(" ");
int N = Integer.parseInt(temp[0]);
int num_genes = Integer.parseInt(temp[1]);
genomes = new char[2*N][num_genes];
for (int i = 0; i < 2*N; i++)
genomes[i] = br.readLine().toCharArray();
//check all things
int count = 0;
int[] c;
boolean isSolution;
for (int i = 0; i < num_genes; i++)
for (int k = i + 1; k < num_genes; k++)
for (int j = k + 1; j < num_genes; j++)
{
isSolution = true;
for (int a = 0; a < 2*N; a++)
{
key = new String(new char[] {genomes[a][i], genomes[a][j], genomes[a][k]});
diff.get(key)[1]++;
if (a < N)
diff.get(key)[0]++;
}
for (String s: diff.keySet())
{
c = diff.get(s);
if (c[0]!= 0 && c[1] > c[0])
isSolution = false;
c[0] = 0; c[1] = 0;
}
if (isSolution)
{
count++;
}
}
//System.out.println(count);
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("cownomics.out")));
pw.println(count);
pw.close();
br.close();
}
}