第三题:
#include<iostream>
#define max 100
using namespace std;
void copy1(int a[],int k,int n)
{
for(int i=k+1;i<=(n-4)/2;i++)
a[i]=a[k];
}
void copy2(int a[],int k,int n)
{
for(int i=k-1;i>(n-4)/2;i--)
a[i]=a[k];
}
int main()
{
int n;
cout<<"输入n的值(n>=4):"<<endl;
cin>>n;
int a[100];
int i,j,k;
for(k=0;k<n;k++) cout<<"T"<<" ";
cout<<endl;
cout<<"T"<<" ";
for(k=0;k<n-2;k++) cout<<"J"<<" ";
cout<<"T"<<endl;
for(i=1;i<=(n-4)/2+1;i++)
{
for(j=1;j<=i;j++)
{
a[j-1]=j;
copy1(a,(j-1),n);
}
for(j=1;j<=i;j++)
{
a[n-4-j]=j;
copy2(a,(n-4-j),n);
}
cout<<"T"<<" "<<"J"<<" ";
for(k=0;k<n-4;k++) cout<<a[k]<<" ";
cout<<"J"<<" "<<"T"<<" ";
cout<<endl;
}
for(i=n-4;i>(n-4)/2+1;i--)
{
for(j=1;j<=i-((n-4)/2+1);j++)
{
a[j-1]=j;
copy1(a,(j-1),n);
}
for(j=1;j<=i-((n-4)/2+1);j++)
{
a[n-4-j]=j;
copy2(a,(n-4-j),n);
}
cout<<"T"<<" "<<"J"<<" ";
for(k=0;k<n-4;k++) cout<<a[k]<<" ";
cout<<"J"<<" "<<"T"<<" ";
cout<<endl;
}
cout<<"T"<<" ";
for(k=0;k<n-2;k++) cout<<"J"<<" ";
cout<<"T"<<endl;
for(k=0;k<n;k++) cout<<"T"<<" ";
cout<<endl;
return 0;
}