Source: Internet
Author: User

• View
• Submit
• Statistics
• Questions
Total time limit:
1000ms
Memory Limit:
65536kB
Describe

With digital 1,2,3,4,..., n*n This n2 number of snakes filled with the scale of N*n Square.

The Serpentine Fill method is:

For each lower left-right diagonal, numbered from top left to bottom right,..., 2n-1; According to the order from small to large, the numbers from small to large to fill in each slash, where numbered odd from the left to the right to fill, numbered even from the top right to the left to fill.

For example, when n=4, the square is filled with the following form:

`1 2 6 73 5 8 134 9 12 1410 11 15 16`
Input
Enter a positive integer not greater than 10 N, representing the number of rows of the square.
Output
The matrix is output, with a single space interval between adjacent two elements.
Sample input
`4`
Sample output
`1 2 6 73 5 8 134 9 12 1410 11 15 16`
• View
• Submit
• Statistics
• Questions
`1#include <iostream>2#include <cstdio>3#include <string>4#include <cstring>5 using namespacestd;6 inta[101][101];7 intMain ()8 {9     intn,t=0;TenCin>>N; One      for(intk=1; k<=n*2-1; k++) A      { -          if(k%2!=0)//odd Diagonal; -           { the                for(inti=n;i>=1; i--) -                { -                     for(intj=1; j<=n;j++) -                     { +                         if(i+j-1==k) -                          { +a[i][j]=++T; A                          } at                     } -                } -           } -           if(k%2==0) -            { -             for(intI=1; i<=n;i++) in                { -                     for(intj=1; j<=n;j++) to                     { +                         if(i+j-1==k) -                          { thea[i][j]=++T; *                          } \$                          Panax Notoginseng                          } -                          } the      } +      } A       for(intI=1; i<=n;i++) the       { +            for(intj=1; j<=n;j++) -            { \$cout<<A[i][j]; \$cout<<" "; -            } -cout<<Endl; the       } -}`

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.