- /*
- **输入n,求n阶最小的拉丁方阵 。n阶拉丁方阵为每一行、
- 每一列都是数字1到n,且每个数字只出现一次。最小拉丁方阵是将方阵的一行一行数连接在一起,
- 组成为一个数,则这个数是最小的。
- 1234
- 2341
- 3412
- 4123
- 思路:第一行为1234,第二行从2开始,第三行是3,第4行是4开头,后面在是连续的
- 数,根据这个特点进行考虑
- */
- #include<iostream>
- using namespace std;
- int main()
- {
- int i,j;
- int n;
- cout<<"请输入N阶:";
- cin>>n;
- for (i=0; i<n; i++) /* 控制行数 */
- {
- for (j=0; j<n; j++) /* 控制每行输出的列的个数*/
- {
- int pos = (i+j)%n+1; /* 输出每列数据*/
- cout<<pos<<" ";
- }
- cout<<endl; /* 输完一行 换行处理*/
- }
- system("pause");
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/191220138150.html
来源: http://www.codesnippet.cn/detail/191220138150.html