-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHmm1.java
More file actions
68 lines (61 loc) · 1.83 KB
/
Copy pathHmm1.java
File metadata and controls
68 lines (61 loc) · 1.83 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
61
62
63
64
65
66
67
68
import java.util.Arrays;
import java.util.Scanner;
/**
*
* @author joar
*/
public class Hmm1 {
public static void main(String[] args) {
readAndSolve();
}
public static void readAndSolve(){
Scanner data=new Scanner(System.in);
Matrix a=new Matrix(data.nextLine());
Matrix b=new Matrix(data.nextLine());
Matrix pi=new Matrix(data.nextLine());
data.close();
System.out.println(pi.multiply(a).multiply(b).string());
}
}
class Matrix {
private final float[][] matrix;
private final int rows;
private final int columns;
private final String stringMatrix;
public Matrix(String inStringMatrix){
String[] listMatrix=inStringMatrix.split(" ");
rows=Integer.valueOf(listMatrix[0]);
columns=Integer.valueOf(listMatrix[1]);
stringMatrix=inStringMatrix;
matrix=new float[rows][columns];
int counter=2;
for(int j=0;j<rows;j++){
for(int k=0;k<columns;k++){
matrix[j][k]=Float.valueOf(listMatrix[counter]);
counter++;
}
}
}
public Matrix multiply(Matrix inMatrix){//returns Matrix*inMatrix
String buildString=rows+ " " + inMatrix.columns;
for(int h=0;h<inMatrix.columns;h++){
for(int i=0; i<rows;i++){
float tmpSum=0;
for(int j=0;j<columns;j++){
tmpSum=tmpSum+inMatrix.matrix[j][h]*matrix[i][j];
}
buildString=buildString+" "+ tmpSum;
}
}
Matrix returnMatrix=new Matrix(buildString);
return returnMatrix;
}
public String string(){
return stringMatrix;
}
public void print(){
for(float[] row: matrix){
System.out.println(Arrays.toString(row));
}
}
}