游客 Signup | Login
中文 | En

2561 - 二维数组打印

通过次数

0

提交次数

0

Time Limit : 1 秒 Memory Limit : 128 MB

输入一个整数n(2<=n<=20),打印一个n*n的矩阵,格式参照样例。

【输入样例

10


【输出样例】

1 2 3 4 5 6 7 8 9 10&nbsp;<br />

2 3 4 5 6 7 8 9 10 9 
3 4 5 6 7 8 9 10 9 8 
4 5 6 7 8 9 10 9 8 7 
5 6 7 8 9 10 9 8 7 6 
6 7 8 9 10 9 8 7 6 5 
7 8 9 10 9 8 7 6 5 4 
8 9 10 9 8 7 6 5 4 3 
9 10 9 8 7 6 5 4 3 2 
10 9 8 7 6 5 4 3 2 1 

<div>
	<br />
</div>

Input

Output

Examples

Input Format


                        

Output Format


                        

Solution C++

#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
	int n;
	int a[21][21];
	cin>>n;
	int g;
	for(int i=1;i<=n;i++)
	{
		g=0;
	    for(int j=i;j<=n;j++)
		{
			cout<<j<<' ';
			g++;
			if(j==n&&g!=n)
				for(int w=j-1;g!=n;w--)
				{
			        cout<<w<<' ';
			        g++;
				}
		}
        if(g==n)
			cout<<endl;
	}
	//system("pause");
}