Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <random>
- #include <algorithm>
- #include <chrono>
- using namespace std;
- struct Pos{
- size_t line;
- size_t row;
- };
- class Cell {
- public:
- Cell(int _val) : val(_val){}
- void setPosition(const Pos& p){
- pos.line = p.line;
- pos.row = p.row;
- }
- size_t Row() const {
- return pos.row;
- }
- size_t Line() const {
- return pos.line;
- }
- int Value() const {
- return val;
- }
- private:
- int val;
- Pos pos;
- };
- size_t Random(default_random_engine &d){
- uniform_int_distribution<> uid(1, 1000);
- return uid(d);
- }
- int main() {
- const int size = 10;
- vector<vector<Cell*>> matrix(size, vector<Cell*>(size));
- vector<Cell*> rowMax;
- default_random_engine dre (chrono::steady_clock::now().time_since_epoch().count());
- for(size_t row = 0; row < size; ++row){
- for(size_t line = 0; line < size; ++line){
- auto cell = new Cell(Random(dre));
- cell->setPosition({row, line});
- matrix[row][line] = cell;
- }
- }
- auto cmp = [](const auto lhs, const auto rhs){ return lhs->Value() < rhs->Value(); };
- for(const auto& line : matrix){
- auto it = max_element(line.begin(), line.end(), cmp);
- rowMax.push_back(*it);
- }
- cout << "Line: ";
- auto it = max_element(rowMax.begin(), rowMax.end(), cmp);
- auto maxLine = std::distance(rowMax.begin(), it);
- cout << maxLine << endl;;
- cout << "Row: ";
- for(size_t i = 0; i<size; ++i){
- cout << matrix.at(maxLine).at(i)->Value() << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement