Advertisement
Guest User

DSkl_B

a guest
Apr 29th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <iostream>
  2. #include<cstdio>
  3.  
  4. using namespace std;
  5.  
  6. int m[1010][1010];
  7.  
  8. int p, q, con, n;
  9.  
  10. void down(){
  11.     while(p + 1 < n && q + 1 < n){
  12.         p++;
  13.         q++;
  14.         printf("%d ",m[p][q]);
  15.         con++;
  16.     }
  17. }
  18.  
  19. void up(){
  20.     while(p - 1 >= 0 && q - 1 >= 0){
  21.         p--;
  22.         q--;
  23.         printf("%d ",m[p][q]);
  24.         con ++;
  25.     }
  26. }
  27.  
  28. int main(){
  29.     int t , ts = 0;
  30.     cin >> t;
  31.     while(t--){
  32.         con = 0;
  33.         cin >> n;
  34.         for(int i = 0; i < n; i++){
  35.             for(int j = 0; j < n; j++){
  36.                 cin >> m[i][j];
  37.             }
  38.         }
  39.         printf("Case #%d: ", ++ts);
  40.         con = 0;
  41.  
  42.         p = n-1;
  43.         q = 0;
  44.  
  45.         con++;
  46.         printf("%d ",m[p][q]);
  47.         while(con != n*n){
  48.            if(p + 1 < n && q + 1 < n)down();
  49.            if(q+1 < n){
  50.                 q = q+1;
  51.                 printf("%d ",m[p][q]);
  52.                 con ++;
  53.            }
  54.            else if(p - 1 >= 0){
  55.                 p = p - 1;
  56.                 printf("%d ",m[p][q]);
  57.                 con++;
  58.            }
  59.  
  60.            if(p - 1 >= 0 && q - 1 >= 0)up();
  61.  
  62.            if(p - 1 >= 0){
  63.                 p = p - 1;
  64.                 printf("%d ",m[p][q]);
  65.                 con++;
  66.            }else if(q + 1 < n){
  67.                q = q + 1;
  68.                printf("%d ",m[p][q]);
  69.                con++;
  70.            }
  71.  
  72.         }printf("\n");
  73.     }return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement