Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F84353375
Un.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Sep 22, 08:01
Size
1 KB
Mime Type
text/x-c
Expires
Tue, Sep 24, 08:01 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20996722
Attached To
R10932 CS-119
Un.cc
View Options
#include <iostream>
#include <vector>
using namespace std;
const string P1("P1 missing or incorrect");
const string WRONG_NB_COL_LGN("Nb columns and/or nb lines incorrect");
const string MATRIX_SQUARE("Matrix is not square");
const string IRREGULAR_CONTENT("Matrix description with incorrect content");
const string DISCONNECTED_GRAPH("Matrix corresponds to a disconnected graph");
void check_bpm(int &n);
void check_bpm(int &n) {
string header;
// cout << "Header P1 ?" << endl;
cin >> header;
if (header != "P1") {
cout << P1 << endl;
exit(0);
}
int c,l;
// cout << "Nombre de colonnes ?" << endl;
cin >> c;
// cout << "Nombre de lignes ?" << endl;
cin >> l;
if (l == c)
n=l;
else {
cout << MATRIX_SQUARE << endl;
exit(0);
}
}
void make_adj(int n,vector<vector<bool>> &tab);
void make_adj(int n,vector<vector<bool>> &tab) {
for (int i(0); i < n; i++) {
char c;
int j(0);
cin >> c;
while(c != '\n') {
if (c == '0' || c == '1') {
tab[i][j]=int(c)-int('0');
j++;
} else if (isspace(c)) {
} else {
cout << IRREGULAR_CONTENT << endl;
exit(0);
}
cin.get(c);
}
if (j != n) {
cout << WRONG_NB_COL_LGN << endl;
exit(0);
}
tab[i][i]=0;
}
for (int i(0); i < n; i++) {
for (int j(0); j < n; j++) {
if (tab[i][j] == 1)
tab[j][i]=1;
}
}
}
int main() {
int n;
check_bpm(n);
vector<vector<bool>> matAdj(n, vector<bool>(n));
make_adj(n,matAdj);
for (int i(0); i < n; i++) {
for (int j(0); j < n; j++) {
cout << matAdj[i][j] << " ";
}
cout << endl;
}
return 0;
}
Event Timeline
Log In to Comment