70,022
社区成员




#include <iostream>
using namespace std;
int min(int x,int y,int z)
{
int a=99999;
if (a>x)
a=x;
if (a>y)
a=y;
if (a>z)
a=z;
return a;
}
int main()
{
int n;
cin >> n;
int i,j,k,s;
for (i=1;i<=n;i++)
{
for (j=1;j<=n+1-i;j++)
{
k=min(i,j,n+2-i-j);
s=3*(k-1)*(n-1)-9*(k-1)*(k-2)/2;
if (i==k)
cout << s+j+1-k << " ";
if (n+2-i-j==k && i!=k && j!=k)
cout << s+n-3*(k-1)+i-k << " ";
if (j==k && i!=k)
cout << 3*k*(n-1)-9*k*(k-1)/2-i+k+1 << " ";
}
cout << endl;
}
return 0;
}
#include <iostream>
#define MAXSIZE 30
using namespace std;
void f(int n)
{
int Matrix[MAXSIZE][MAXSIZE];
int max_value=n*(n+1)/2;
int row=1,colum=1;
int temp_value=1;
int edge=n;
int i,j;
while (edge>0)
{
//right
for (i=0;i<edge;i++)
{
Matrix[row][colum]=temp_value;
colum++;
temp_value++;
}
//change to 对角线
row++;
colum-=2;
//对角线
for (i=0;i<edge-1;i++)
{
Matrix[row][colum]=temp_value;
temp_value++;
row++;
colum--;
}
//change to up
row-=2;
colum++;
for (i=0;i<edge-2;i++)
{
Matrix[row][colum]=temp_value;
row--;
temp_value++;
}
//change to new right
row++;
colum++;
if (temp_value>max_value)
{
break;
}
edge-=3;
}
//show matrix
for (i=1;i<=n;i++)
{
for (j=1;j<=n+1-i;j++)
{
cout<<Matrix[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
}
int main()
{
int n;
cin>>n;
while (n>0)
{
f(n);
cin>>n;
}
}