-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp3.cpp
67 lines (51 loc) · 1.22 KB
/
temp3.cpp
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
#include<iostream>
#include<vector>
#include<fstream>
using namespace std;
typedef long long ll;
ifstream yyy("input.txt");
ofstream zzz("output.txt");
int main()
{
int n1, m1;
yyy >> n1 >> m1;
vector<vector<ll>>array1(n1, vector<ll>(m1));
for (int i = 0; i < n1; i++) {
for (int j = 0; j < m1; j++)
yyy >> array1[i][j];
}
int n2, m2;
yyy >> n2 >> m2;
vector<vector<ll>>array2(n2, vector<ll>(m2));
for (int i = 0; i < n2; i++) {
for (int j = 0; j < m2; j++)
yyy >> array2[i][j];
}
// multipliing two matrices.
if(n2 != m1){
zzz << "Invalid input" << endl;
return 0;
}
vector<vector<ll>>array3(n1, vector<ll>(m2));
int sum = 0;
for(int i = 0; i< n1; i++)
{
for(int j = 0; j< m2; j++)
{
sum = 0;
for(int k = 0; k < m1; k++)
{
sum += array1[n1][k] * array2[k][m2];
}
array3[i][j] = sum;
}
}
for(int i=0 ; i< n1; i++)
{
for(int j= 0; j < m2; j++)
{
zzz << array3[i][j] << " ";
}
zzz << endl;
}
}