-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix_Project.cpp
More file actions
97 lines (94 loc) · 1.88 KB
/
Copy pathMatrix_Project.cpp
File metadata and controls
97 lines (94 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <sstream>
#include <stdlib.h>
using namespace std;
int GetMatrix (string s,float x[100][100], int SIZE1[100]){
string data;
int counter = 0;int value = 0;
for (int i=0;i<s.length();i++){
if (s[i] == '[' || s[i] == ';' || s[i] == ']')
{
if (s[i] == ']'){
s[i] = ' ';
for (int g=i;g<s.length();g--){
if(s[g] == ';'){
data = s.substr(g+1,i+1);
counter++;
break;
}
}}
for (int g=i;g<s.length();g++){
if (s[g] == ';' ){
data = s.substr(i+1,g-1);
data += ' ';
i = g;
counter++;
break;
}
}
int coun = 0 , see = 0;
for (int j=0;j<data.length();j++){
if (data[j] == ' '){
string cc = data.substr(coun,j);
x[counter-1][see] = atof(cc.c_str());
coun = j+1;
see++;
}
}
SIZE1[value] = see;
value++;
}
}
return counter;
}
int main(){
string Input1,Input2;string Op;
getline(cin,Input1);
getline(cin,Op);
getline(cin,Input2);
float x[100][100];
float y[100][100];
float z[100][100];
int SIZE1[100];
int SIZE2[100];
int size_mat1 = GetMatrix (Input1,x,SIZE1);
int size_mat2 = GetMatrix (Input2,y,SIZE2);
if (Op == "+")
{
for (int i=0;i<size_mat1;i++)
for(int j=0;j<SIZE1[i];j++)
z[i][j] = x[i][j] + y[i][j];
}
else if (Op == "-")
{
for (int i=0;i<size_mat1;i++)
for(int j=0;j<SIZE1[i];j++)
z[i][j] = x[i][j] + y[i][j];
}
else
{
for (int i=0;i<size_mat1;i++)
for(int j=0;j<SIZE1[i];j++)
z[i][j] = x[i][j] * y[i][j];
}
for (int i=0;i<size_mat1;i++){
if (i == 0)
cout<<"[";
for(int j=0;j<SIZE1[i];j++){
if (j == SIZE1[i]-1){
cout<<z[i][j];
}
else
cout<<z[i][j]<<" ";
}
if (i == size_mat1-1)
cout<<"]"<<endl;
else
cout<<";";
}
system("pause");
return 0;
}