比如:
5行4列数组:
3 5 6 8
9 6 4 8
3 5 6 8
4 8 2 7
4 8 2 7
这个数组可分成3类。
bool compare(int A[],int B[],int size){
for (int i = 0;i < size ; ++ i)
if (A[i] != B[i])
return 0;
return 1;
}
int main(){
const int row = 7;
const int size = 4;
int count = 0;
int A[row][size] = {{3,3,6,8},{3,3,6,8},{4,3,6,8},{4,3,6,8},
{3,3,6,2},{3,3,6,8},{3,3,6,2}};
for (int i = 0;i < row; ++i){
bool YorN = 1;
for (int check = i;check >= 0;--check){
if (i == 0)
break;
if(compare(A[i],A[check-1],size)){
YorN = 0;
break;
}
}
if (YorN){
for (int j = 0;j < row; ++j){
if (i != j){
if (compare(A[i],A[j],size)){
count++;
break;
}
}
}
}
}
cout << count << endl;
return 0;
}
输出的 count 即为有几类!
总觉得代码太烦琐,希望有人有更好的方法!