#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <unordered_map>
// Helper function to convert a vector to a string (for row comparison)
std::string vectorToString(const std::vector<int>& row) {
std::ostringstream oss;
for (int num : row) {
oss << num << ",";
}
return oss.str();
}
void findRepeatedRows(const std::vector<std::vector<int>>& matrix) {
std::unordered_map<std::string, int> rowCount;
for (const auto& row : matrix) {
std::string pattern = vectorToString(row);
rowCount[pattern]++;
}
std::cout << "Repeated Rows:\n";
for (const auto& entry : rowCount) {
if (entry.second > 1) {
std::cout << "Row: [" << entry.first << "] - Repeated " << entry.second << " times\n";
}
}
}
int main() {
std::vector<std::vector<int>> matrix = {
{1, 2, 3},
{4, 5, 6},
{1, 2, 3},
{7, 8, 9},
{4, 5, 6},
{0, 1, 2},
{4, 5, 6},
};
findRepeatedRows(matrix);
}
/*
run:
Repeated Rows:
Row: [4,5,6,] - Repeated 3 times
Row: [1,2,3,] - Repeated 2 times
*/