代码:
#include <stdio.h>
#include<iostream>
using namespace std;
int a[100][100]{};
void roundrob(int k, int n)
{
if (n == 2)
{
a[k][0] = k + 1;
a[k][1] = k + 2;
a[k + 1][0] = k + 2;
a[k + 1][1] = k + 1;
}
else
{
roundrob(k,n / 2);
roundrob(k + n / 2,n / 2);
}
for (int i = k; i < k + n / 2; i++)
{
for (int j = n / 2; j < n; j++)
{
a[i][j] = a[i + n / 2][j - n / 2];
}
}
for (int i = k + n / 2; i < k + n; i++)
{
for (int j = n / 2; j < n; j++)
{
a[i][j] = a[i - n / 2][j - n / 2];
}
}
}
int determine(int n)
{
if (n % 2 == 0)
{
if (n / 2 == 1) return 1;
determine(n / 2);
}
else
{
cout << "输入人数不合法" << endl;
return 0;
}
}
int main()
{
int n;
int k;
cout << "请输入参赛人数" << endl;
cin >> n;
if (determine(n) == 1)
{
cout << "请输入第一个选手编号" << endl;
cin >> k;
k = k - 1;
roundrob(k, n);
int i = 0, j = 0;
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
}
if (determine(n) == 0)
{
return 0;
}
}