Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

563624 views
1
// reads a matrix in Normalizz format and prints the transpose to stdout
2
// again in Normaliz format
3
4
#include <stdlib.h>
5
#include <vector>
6
#include <list>
7
#include <map>
8
9
#include <sstream>
10
#include <fstream>
11
#include <iostream>
12
#include <algorithm>
13
using namespace std;
14
15
16
vector<vector<int> > readMat(const string& project){
17
// reads one matrix from .in file
18
19
string name_in=project;
20
const char* file_in=name_in.c_str();
21
ifstream in;
22
in.open(file_in,ifstream::in);
23
if (in.is_open()==false){
24
cerr << "Cannot find input file" << endl;
25
exit(1);
26
}
27
28
int nrows,ncols;
29
in >> nrows;
30
in >> ncols;
31
32
if(nrows==0 || ncols==0){
33
cerr << "Matrix empty" << endl;
34
exit(1);
35
}
36
37
38
int i,j,entry;
39
vector<vector<int> > result(nrows);
40
41
for(i=0;i<nrows;++i)
42
for(j=0;j<ncols;++j){
43
in >> entry;
44
result[i].push_back(entry);
45
}
46
return(result);
47
}
48
49
int main(int argc, char* argv[])
50
{
51
52
if(argc<2){
53
cerr << "No input file given" << endl;
54
exit(1);
55
}
56
string input_name=argv[1];
57
vector< vector<int > > M;
58
M=readMat(input_name);
59
cout << M[0].size() << " " << M.size() << endl;
60
for(size_t i=0;i<M[0].size();++i){
61
for(size_t j=0;j<M.size();++j)
62
cout << M[j][i] << " ";
63
cout << endl;
64
}
65
return(0);
66
}
67
68