题解 | #蛇形矩阵#
蛇形矩阵
http://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e
#include <string.h>
#include <iostream>
using namespace std;
int main()
{
int a;
int b[100];
while(cin>>a)
{
b[0]=1;
for(int i=1;i<a;i++)
{
b[i]=b[i-1]+i+1;
}
for(int i=0;i<a;i++)
{
for(int j=i;j<a;j++)
{
cout<<b[j]-i<<' ';
}
cout<<'\n';
}
}
return(0);
}
#include <iostream>
using namespace std;
int main()
{
int a;
int b[100];
while(cin>>a)
{
b[0]=1;
for(int i=1;i<a;i++)
{
b[i]=b[i-1]+i+1;
}
for(int i=0;i<a;i++)
{
for(int j=i;j<a;j++)
{
cout<<b[j]-i<<' ';
}
cout<<'\n';
}
}
return(0);
}