Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FN "matrix"
- #include<cstdio>
- #include<cctype>
- #include<iostream>
- #include<fstream>
- #include<functional>
- #include<utility>
- #include<vector>
- #include<stack>
- #include<map>
- #include<queue>
- #include<deque>
- #include<cstdlib>
- #include<cmath>
- #include<algorithm>
- #include<set>
- #include<complex>
- #include<cstring>
- #include<string>
- #include<cassert>
- #include<iomanip>
- using namespace std;
- typedef long long LL;
- #define pb push_back
- #define mp make_pair
- #define fi first
- #define se second
- #define all(n) (n).begin(), (n).end()
- #define EPS 1e-9
- #define INF 1e9
- #define forn(i, n) for(int (i) = 0; (i) < (n); ++(i))
- #define forab(i, a, b) for(int (i) = a; (i) <= (b); ++(i))
- #define forba(i, b, a) for(int (i) = b; (i) >= (a); --(i))
- #define forit(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
- vector <vector <double> > a,b;
- int main(){
- #ifdef FN
- freopen(FN".in", "r", stdin);
- freopen(FN".out", "w", stdout);
- #endif
- int n;
- int m;
- scanf("%d%d", &n, &m);
- a.resize(n);
- forn(i, n){
- forn(j, m){
- double q;
- scanf("%lf", &q);
- a[i].pb(q);
- }
- }
- int h;
- int w;
- scanf("%d%d", &h, &w);
- b.resize(h);
- forn(i, h){
- forn(j, w){
- double q;
- scanf("%lf", &q);
- b[i].pb(q);
- }
- }
- if(m!=h){
- printf("Operation is undefined for these matrixes\n");
- return 0;
- }
- vector <vector <double> > c(n);
- forn(i, n){
- c[i].resize(w, 0);
- forn(j, w){
- forn(k, m){
- c[i][j]+=a[i][k]*b[k][j];
- }
- }
- }
- forn(i, n){
- forn(j, w){
- printf("%2.3lf ", c[i][j]);
- } printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment