3. 2X2 Squares in Matrix
Не мога да разбера защо ми гърми, ако някой може да помогне.
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
using namespace std;
vector<int> read1Dvec() {
vector < int> vec1D;
string line;
getline(cin, line);
istringstream istr(line);
int currNum = 0;
while (istr >> currNum) {
vec1D.push_back(currNum);
}
return vec1D;
}
vector<vector<int>> vec2D(int rows) {
vector<vector<int>> vec2(rows);
for (vector<int>& row : vec2) {
row = read1Dvec();
}
return vec2;
}
void printFind(const vector<vector<int>>& vecD, int cols) {
int counter = 0;
for (size_t i = 0; i < vecD.size(); ++i) {
for (size_t j = 0; j < cols; j++) {
cout << vecD[i][j];
if (vecD[i][j] == vecD[i + 1][j]) {
if (vecD[i][j] == vecD[i][j + 1]) {
if (vecD[i][j] == vecD[i + 1][j + 1]) {
counter++;
}
}
}
}
}
cout << counter;
}
int main() {
int cols = 0;
int rows = 0;
cin >> cols;
cin >> rows;
cin.ignore();
vector<vector<int>> vecD = vec2D(rows);
printFind(vecD, cols);
return 0;
}
//3 4
//A B B D
//E B B B
//I J B B