跳到正文

个人记录

matrix

cyf_chenyf约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年11月21日
收录
2026年11月21日
更新
2026年11月21日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5;
int x,y,xx,yy,a[N][N],b[N][N],ans[N][N];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>y>>x;
	for(int i=1;i<=x;i++){
		for(int j=1;j<=y;j++){
			cin>>a[i][j];
		}
	}
	cin>>xx>>yy;
	for(int i=1;i<=xx;i++){
		for(int j=1;j<=yy;j++){
			cin>>b[i][j];
		}
	}
	if(y!=xx){
		cout<<"Wrong!";
		return 0;
	}
	for(int i=1;i<=x;i++){
		for(int j=1;j<=yy;j++){
			int sum=0;
			for(int k=1;k<=y;k++)sum+=a[i][k]*b[k][j];
			ans[i][j]=sum;
		}
	}
	for(int i=1;i<=x;i++){
		for(int j=1;j<=yy;j++){
			cout<<ans[i][j]<<' ';
		}
		cout<<'\n';
	}
	return 0;
} 
原文