沐里纷纷


私信TA

用户名:Epoch

访问量:62725

签 名:

我不会算法

等  级
排  名 37
经  验 12806
参赛次数 1
文章发表 172
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

不会算法

#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100;

struct mat{
	int m[maxn][maxn];
	int row;
	int col;
};

mat operator * (mat a, mat b){
	mat ret;
	ret.row = a.row;
	ret.col = b.col;
	int n = a.col;
	for(int i = 0; i < a.row; i++){
		for(int j = 0; j < b.col; j++){
			int x = 0;
			for(int k = 0; k < n; k++){
				x += a.m[i][k] * b.m[k][j];
			}
			ret.m[i][j] = x;
		}
	} 
	return ret;
}

int main(void){
	mat a,b,c;
	a.row = 2;
	a.col = 3;
	b.row = 3;
	b.col = 2;
	while(cin >> a.m[0][0] >> a.m[0][1] >> a.m[0][2]){
		for(int i = 1; i < a.row; i++){
			for(int j = 0; j < a.col; j++){
				cin >> a.m[i][j];
			} 
		}
		for(int i = 0; i < b.row; i++){
			for(int j = 0; j < b.col; j++){
				cin >> b.m[i][j];
			} 
		}
		c = a * b;
		for(int i = 0; i < c.row; i++){
			for(int j = 0; j < c.col; j++){
				cout << c.m[i][j] << " ";
			} 
			cout << endl;
		}
	}

	return 0;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区