```c++
faulttestM = { {1,1,1,0,0,1,0,1,0,0},
{0,0,0,1,0,0,1,1,0,1},
{0,0,1,0,1,1,1,1,1,1},
{0,0,0,1,0,0,1,1,0,1},
{1,1,1,0,0,1,0,1,0,0} };
如上矩阵,需要删除相同的行和列,请问该怎么写代码,我自己写的只能删除一行T T
vector <int> reRow;
vector <int> reCol;
int b = 0;
//查找相同的行,放入reRow数组中
for (int i = 0; i < row; i++)
{
for (int count1 = i + 1; count1 < row; count1++)
{
int a = 0;
for (int j = 0; j < rol; j++)
{
if (faulttestM[i][j] == faulttestM[count1][j])
{
a++;
continue;
}
else if (faulttestM[i][j] != faulttestM[count1][j])
{
break;
}
}
if (a == rol)
{
b++;
if (count(reRow.begin(), reRow.end(), count1))
{
break;
}
else
{
reRow.push_back(count1);
}
}
}
}
cout << "检查re中是否存在数值:" << reRow[0] << endl;
cout << "check the size of reRow:" << reRow.size() << endl;
//查找相同的列,放入reCol数组中
int c = 0;
for (int j = 0; j < rol; j++)
{
for (int count2 = j + 1; count2 < rol; count2++)
{
int a = 0;
for (int i = 0; i < row; i++)
{
if (faulttestM[i][j] == faulttestM[i][count2])
{
a++;
continue;
}
else if (faulttestM[i][j] != faulttestM[i][count2])
{
break;
}
}
if (a == row)
{
c++;
if (count(reCol.begin(), reCol.end(), count2))
{
break;
}
else
{
reCol.push_back(count2);
}
}
}
}
cout << "check the size of reCol:" << reCol.size() << endl;
int optrow = row - reRow.size();
int optrol = rol - reCol.size();
cout << "row : " << row << endl;
cout << "rol : " << rol << endl;
cout << "optrow : " << optrow << endl;
cout << "optrol : " << optrol << endl;
int** optftmatrix;
//矩阵初始化
optftmatrix = new int* [row];
for (int i = 0; i < row; i++)
optftmatrix[i] = new int[rol];
for (int i = 0; i < row; i++)
{
for (int j = 0; j < rol; j++)
{
optftmatrix[i][j] = 0;
}
}//初始化结束
for (int k = 0; k < reRow.size(); k++)
{
cout << "reRow里的值:" << reRow[k] << endl;
}
for (int i = 0; i < reCol.size(); i++)
{
cout << "reCol里的值:" << reCol[i] << endl;
}
cout << "检查矩阵中的值:"<<faulttestM[0][5]<<" "<<faulttestM[1][3] << endl;
int r0 = 0, c0 = 0;
for (int i = 0; i < row; i++)
{
for (int k = 0; k < reRow.size(); k++)
{
if (i == reRow[k])
{
r0 = 1;
}
else
{
r0 = 0;
}
int delColCount = -1;
for (int j = 0; j < rol; j++)
{
for (int p = 0; p < reCol.size(); p++)
{
if (j < reCol[p])
{
c0 = 0;
}
else
{
c0 = 1;
if (j + 1 == rol)
{
continue;
}
}
/*for (int k = 1; k < reCol.size(); k++)
{
if (reCol[k - 1] < j < reCol[k])
{
delColCount += 1;
}
else if (reCol[k] < j < reCol[k + 1])
{
delColCount += 2;
}*/
//}
optftmatrix[i][j] = faulttestM[i + r0][j + c0];
}
}
}
}
```