-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathup_trianger.cpp
More file actions
78 lines (71 loc) · 1.5 KB
/
Copy pathup_trianger.cpp
File metadata and controls
78 lines (71 loc) · 1.5 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
#include <iostream>
#include <fstream>
using namespace std;
//Comments: prints a n-by-n matrix
void printMatrix(double **Q, int n)
{
for (int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
cout << Q[i][j] << " ";
cout << endl;
}
}
//Comments: prints a n-by-n matrix
void printMatrixUpTriangular(double **Q, int n)
{
for (int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
{
if(j<i)cout<<"& ";
else if(j==i)cout << Q[i][j]<<" & ";
else cout << Q[i][j]+Q[j][i] << " & ";
}
cout << endl;
}
}
void read_qubo(int &n, double **&Q) {
// Start of: initializing Q
string line;
getline(cin,line);
std::size_t pos = line.find(" ");
if(pos!=std::string::npos)
{
line = line.substr(0,pos);
}
n = atoi(line.c_str());
Q = new double*[n];
for (int i=0; i<n; i++)
{
Q[i] = new double[n];
for (int j=0; j<n; j++)
Q[i][j] = 0;
}
for (int i=0; i<n; i++)
{
for(int j=0;j<n;j++)
cin >> Q[i][j];
}
}
int main(int argc, char* argv[])
{
int n,k;
double **Q;
read_qubo(n,Q);
for (int i=0; i<n; i++)
{
for(int j=i+1;j<n;j++)
{
//Q[i][j]=Q[i][j]+Q[j][i];
Q[j][i]=Q[i][j];
}
}
cout<<n<<endl;
//printMatrix(Q,n);
printMatrixUpTriangular(n,Q);
for (int i=0; i<n; i++)
delete [] Q[i];
delete [] Q;
return 0;
}