Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- std::vector<std::vector<char>> readMatrix(int& rows, int& cols) {
- std::cin >> rows >> cols;
- std::vector<std::vector<char>> matrix;
- for (int i = 0; i < rows; ++i) {
- std::vector<char> row;
- for (int j = 0; j < cols; ++j) {
- char c; std::cin >> c;
- row.push_back(c);
- }
- matrix.push_back(row);
- }
- return matrix;
- }
- void findSquares(std::vector<std::vector<char>>& matrix) {
- int squaresCounter = 0;
- for (int i = 0; i < matrix.size(); ++i) {
- for (int j = 0; j < matrix[i].size(); ++j) {
- if (i + 1 < matrix.size() && j + 1 < matrix[i].size()) {
- if (matrix[i][j] == matrix[i][j + 1] && matrix[i + 1][j] == matrix[i + 1][j + 1] && matrix[i][j] == matrix[i + 1][j]) {
- squaresCounter++;
- }
- }
- }
- }
- std::cout << squaresCounter;
- }
- int main() {
- int rows, cols;
- std::vector<std::vector<char>> matrix = readMatrix(rows, cols);
- findSquares(matrix);
- }
Advertisement
Add Comment
Please, Sign In to add comment