一个很有趣的排列方法:
#include<iostream>
using namespace std;
struct diamond
{
int color; //颜色编号
int shape; //形状编号
int use; //是否已经排列,未排列为1
};
int main(){
int N=5;
diamond a[N*N+1];
for(int i=1;i<=N*N;i++)
{
a[i].color=(i-1)/N+1;
a[i].shape=(i-1)%N+1;
a[i].use=1;
}
for(int i=1;i<=N*N;i++)
{
cout<<a[i].color<<" ";
cout<<a[i].shape;
cout<<endl;
}
return 0;
}
运行结果为: