循环赛日程表

来源:互联网 发布:阿里巴巴国际淘宝网 编辑:程序博客网 时间:2024/04/29 00:25
#include<stdio.h>
#define n 8
int main()
{
int i,j,k,index,p,q,direction;
int a[8][8];
for(i = 0;i < n;i ++){
a[0][i] = i + 1;
}
k = 1;
index = 1;
while(k < n){
direction = 1;
for(p = index;p < k + index;p ++){
for(q = 0;q < n;q ++){
a[p][q] = a[p - k][q + k * direction];
if((q + 1) % k == 0){
direction = direction * (-1);
}
}

}
index = index + k;
k = k * 2;
}


for(i = 0;i < n;i ++){
for(j = 0;j < n;j ++)
printf("%2d",a[i][j]);
putchar('\n');
}
return 0;
}
0 0
原创粉丝点击