Problem F: calculating the product of two matrices
Time limit: 1 Sec memory limit: 32 MB
Flower offering: 38 solution: 33
[flower offering] [wreath] [TK question bank]
Title Description
Calculate the product of two matrices, the first is a 2 * 3 matrix, the second is a 3 * 2 matrix, the result is a 2 * 2 matrix.
input
The input contains multiple groups of data. First, enter a 2 * 3 matrix, and then enter a 3 * 2 matrix.
output
Output the product of two matrices.
sample input
1 1 1
1 1 1
1 1
1 1
1 1
sample output
3 3
3 3
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <fstream>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <ctime>
using namespace std;
typedef struct
{
int n;
int c;
}Num;
bool cmp(Num a, Num b)
{
if (a.c != b.c) return a.c > b.c;
return a.n < b.n;
}
int main()
{
#ifdef _DEBUG
//freopen("data.txt", "r+", stdin);
fstream cin("data.txt");
#endif // _DEBUG
int a[2][3], b[3][2];
while (cin >> a[0][0])
{
cin >> a[0][1] >> a[0][2] >> a[1][0] >> a[1][1] >> a[1][2];
cin >> b[0][0] >> b[0][1] >> b[1][0] >> b[1][1] >> b[2][0] >> b[2][1];
for (int i = 0; i < 2; ++i)
{
for (int res = 0, j = 0; j < 2; ++j)
{
res = a[i][0] * b[0][j] + a[i][1] * b[1][j] + a[i][2] * b[2][j];
cout << res;
if (j != 1)
cout << " ";
}
cout << endl;
}
}
#ifdef _DEBUG
cin.close();
#ifndef _CODEBLOCKS
system("pause");
#endif // !_CODEBLOCKS
#endif // _DEBUG
return 0;
}
/**************************************************************
Problem: 1970
User: Sharwen
Language: C++
Result: Immortals
Time:2 ms
Memory:1704 kb
****************************************************************/