Pagini recente » Cod sursa (job #1860163) | Cod sursa (job #876258) | Cod sursa (job #85446) | Cod sursa (job #948985) | Cod sursa (job #2263932)
//
// main.cpp
// Matrix
//
// Created by Darius Buhai on 13/10/2018.
// Copyright © 2018 Darius Buhai. All rights reserved.
//
#include <iostream>
#include <fstream>
using namespace std;
class matrix
{
protected:
int mat[100][100];
int l,c;
public:
/// constructori
matrix(){
l = c = -1;
}
matrix(int m1, int n1){
l = m1;
c = n1;
for(int i=0;i<m1;i++)
for(int j=0;j<n1;j++)
mat[i][j] = 0;
}
matrix(int b[1000][1000], int m1, int n1){
for(int i=0;i<m1;i++)
for(int j=0;j<n1;j++)
mat[i][j] = b[i][j];
l = m1;
c = n1;
}
/// getteri, setteri
void setAttr(int i, int j, int x)
{
mat[i][j] = x;
}
int getAttr(int i, int j)
{
return mat[i][j];
}
int* operator[](const int &i)
{
return mat[i];
}
/// operatori
matrix &operator=(matrix b);
matrix operator+(matrix b);
matrix operator+=(matrix b);
matrix operator-(matrix b);
matrix operator-=(matrix b);
matrix operator>(matrix b);
matrix operator>=(matrix b);
matrix operator<(matrix b);
matrix operator<=(matrix b);
matrix operator*(matrix b);
matrix operator/(matrix b);
friend istream &operator>> (istream &cin, matrix &b);
friend ostream &operator<< (ostream &cout, matrix &b);
};
matrix &matrix::operator=(matrix b)
{
l = b.l;
c = b.c;
for(int i=0;i<b.l;i++)
for(int j=0;j<b.c;j++)
mat[i][j] = b.mat[i][j];
return *this;
}
matrix matrix::operator+(matrix b)
{
matrix r(l,c);
for(int i=0;i<l;i++)
for(int j=0;j<c;j++)
r.mat[i][j] = mat[i][j] + b.mat[i][j];
return r;
}
matrix matrix::operator+=(matrix b)
{
*this = *this + b;
return *this;
}
matrix matrix::operator-(matrix b)
{
matrix r(l,c);
for(int i=0;i<l;i++)
for(int j=0;j<c;j++)
r.mat[i][j] = mat[i][j]-b.mat[i][j];
return r;
}
matrix matrix::operator-=(matrix b)
{
*this = *this - b;
return *this;
}
matrix matrix::operator*(matrix b)
{
matrix r(l,b.c);
for(int i=0;i<r.l;i++)
for(int j=0;j<r.c;j++){
r.mat[i][j] = 0;
for(int k=0;k<c;k++)
r.mat[i][j] += mat[i][k] * b.mat[k][j];
}
return r;
}
istream &operator>> (istream &cin, matrix &b)
{
int x;
if(b.l==-1 || b.c==-1){
cout<<"l = ";
cin>>b.l;
cout<<"c = ";
cin>>b.c;
cout<<endl;
}
for(int i=0;i<b.l;i++)
for(int j=0;j<b.c;j++){
cin>>x;
b.mat[i][j] = x;
}
return cin;
}
ostream &operator<<(ostream &cout,matrix &b)
{
for(int i=0;i<b.l;i++){
for(int j=0;j<b.c;j++)
cout<<b.mat[i][j]<<" ";
cout<<endl;
}
return cout;
}
void iepuri()
{
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
int t, n;
fin>>t;
for(int k=0;k<t;k++){
matrix m1(1,3), m2(3,1);
fin>>m1[0][0]>>m1[0][1]>>m1[0][2];
fin>>m2[2][0]>>m2[1][0]>>m2[0][0];
fin>>n;
for(int i=0;i<3;i++){
matrix p = m1*m2;
for(int j=2;j>i;j--)
m2[j][0] = m2[j-1][0];
m2[i][0] = p[0][0];
}
fout<<m2[n-3][0]<<endl;
}
}
int main() {
iepuri();
return 0;
}