using System;
using System.Collections.Generic;
class RepeatedRowsFinder
{
static void Main()
{
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);
}
static void FindRepeatedRows(int[,] matrix) {
HashSet<string> seenRows = new HashSet<string>();
HashSet<string> repeatedRows = new HashSet<string>();
int rows = matrix.GetLength(0);
int cols = matrix.GetLength(1);
for (int i = 0; i < rows; i++) {
string rowString = RowToString(matrix, i, cols);
if (!seenRows.Add(rowString))
{
repeatedRows.Add(rowString);
}
}
if (repeatedRows.Count == 0) {
Console.WriteLine("No repeated rows found.");
}
else {
Console.WriteLine("Repeated rows:");
foreach (var row in repeatedRows) {
Console.WriteLine(row);
}
}
}
static string RowToString(int[,] matrix, int rowIndex, int cols) {
List<string> rowElements = new List<string>();
for (int j = 0; j < cols; j++) {
rowElements.Add(matrix[rowIndex, j].ToString());
}
return string.Join(",", rowElements);
}
}
/*
run:
Repeated rows:
1,2,3
4,5,6
*/