Base exercise back shape fetch number

Source: Internet
Author: User

Problem DescriptionThe back shape is taken by the number of edges along the matrix, if the current direction is numerous or has been taken, then left 90 degrees. Starts at the upper-left corner of the matrix, in a downward direction. Input FormatThe first line of input is two positive integers of not more than 200 m, N, which represent the rows and columns of the matrix. Next the M line is n integers per row, representing the matrix. output FormatOutput is only one row, the number of total mn, the input matrix is the return of the results obtained. The number is separated by a space, and there is no extra space at the end of the line. Sample Input
3 3 1 2 3 4 5 6 7 8 9
Sample Output
1 4 7 8 9 6 3 2 5
Sample Input
3 2 1 2 3 4 5 6
Sample Output
1 3 5 6 4 2

Kam SAC 1

Looping, marking.

Kam SAC 2

Use multiple loops to process, or you can simplify the judgment of loops by counting the number of tags you have taken.

Test code

1#include <stdio.h>2 3 intMain ()4 {5     intm, n, tot =-1, I, j, x =-1, y =0;6     inta[ $][ $];7 8scanf"%d%d", &m, &n);9 Ten      for(i =0; I < m; i++) One     { A          for(j =0; J < N; J + +) -         { -scanf"%d", &a[i][j]); the         } -     } -  -      while(Tot < M *N) +     { -          while(x +1< m && A[x +1][Y]! =-1) +         { Aprintf"%d", a[++X] [y]); atA[x][y] =-1; -tot++; -         } -          while(Y +1< n && A[x][y +1] != -1) -         { -printf"%d", a[x][++y]); inA[x][y] =-1; -tot++; to         } +          while(X-1>=0&& A[x-1][Y]! =-1) -         { theprintf"%d", a[--X] [y]); *A[x][y] =-1; $tot++;Panax Notoginseng         } -          while(Y-1>=0&& A[x][y-1] != -1) the         { +printf"%d", a[x][--y]); AA[x][y] =-1; thetot++; +         } -     } $     return 0; $}

Base exercise back shape fetch number

Contact Us

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.