-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
64 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,67 @@ | ||
name: C/C++ CI | ||
#include <iostream> | ||
#include <vector> | ||
#include <stdexcept> | ||
using namespace std; | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
class Matrix { | ||
private: | ||
vector<vector<int>>data; | ||
int num_rows; | ||
int num_cols; | ||
public: | ||
Matrix() : num_rows(0), num_cols(0) { | ||
|
||
jobs: | ||
build: | ||
} | ||
Matrix(int rows, int cols) : num_rows(rows), num_cols(cols) { | ||
if (rows < 0 || cols < 0) { | ||
throw out_of_range("Out of range"); | ||
} | ||
data.resize(rows, vector<int>(cols, 0)); | ||
} | ||
Matrix(const Matrix& other) : num_rows(other.num_rows), num_cols(other.num_cols), data(other.data) { | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: configure | ||
run: ./configure | ||
- name: make | ||
run: make | ||
- name: make check | ||
run: make check | ||
- name: make distcheck | ||
run: make distcheck | ||
} | ||
Matrix(Matrix&& other) noexcept : num_rows(other.num_rows), num_cols(other.num_cols), data(move(other.data)) { | ||
other.num_rows = 0; | ||
other.num_cols = 0; | ||
} | ||
void Reset(int rows, int cols) { | ||
if (rows < 0 || cols < 0) { | ||
throw out_of_range("Out of range"); | ||
} | ||
num_rows = rows; | ||
num_cols = cols; | ||
data.assign(rows, vector<int>(cols, 0)); | ||
} | ||
int At(int row, int col) const { | ||
if (row < 0 || row >= num_rows || col < 0 || col >= num_cols) { | ||
throw out_of_range("Index out of bounds"); | ||
} | ||
return data[row][col]; | ||
} | ||
int& At(int row, int col) { | ||
if (row < 0 || row >= num_rows || col < 0 || col >= num_cols) { | ||
throw out_of_range("Index out of bounds"); | ||
} | ||
return data[row][col]; | ||
} | ||
int GetRows() const { | ||
return num_rows; | ||
} | ||
int GetCols() const { | ||
return num_cols; | ||
} | ||
friend istream& operator>>(istream& is, Matrix& matrix) { | ||
int rows, cols; | ||
is >> rows >> cols; | ||
matrix.Reset(rows, cols); | ||
for (int i = 0; i < rows; ++i) { | ||
for (int j = 0; j < cols; ++j) { | ||
is >> matrix.At(i, j); | ||
} | ||
} | ||
return is; | ||
} | ||
friend ostream& operator<<(ostream& os, const Matrix& matrix) { | ||
os << matrix.num_rows << " " << matrix.num_cols << "\n"; | ||
for (int i = 0; i < matrix.num_rows; ++i) |