Advertisement
Spocoman

03. Squares in Matrix

Jan 27th, 2024
876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     int row, col;
  10.     cin >> row >> col;
  11.     cin.ignore();
  12.  
  13.     char chr;
  14.     string line;
  15.  
  16.     vector<vector<char>> matrix;
  17.  
  18.     for (int i = 0; i < row; i++) {
  19.         getline(cin, line);
  20.         istringstream ss(line);
  21.         vector<char> currentRow;
  22.  
  23.         while (ss >> chr) {
  24.             currentRow.push_back(chr);
  25.         }
  26.  
  27.         matrix.push_back(currentRow);
  28.     }
  29.  
  30.     int counter = 0;
  31.  
  32.     for (int i = 0; i < row - 1; i++) {
  33.         for (int j = 0; j < col - 1; j++) {
  34.             chr = matrix[i][j];
  35.             if (chr == matrix[i][j + 1] &&
  36.                 chr == matrix[i + 1][j] &&
  37.                 chr == matrix[i + 1][j + 1]) {
  38.                 counter++;
  39.             }
  40.         }
  41.     }
  42.  
  43.     cout << counter << endl;
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement