Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.  
  7.     int a, i, j;
  8.  
  9.     cin >> a;
  10.  
  11.     int M[2005][2005];
  12.  
  13.     for(i=0, j=0;j<=2*a-2, i<=2*a-2;j++){
  14.  
  15.         if(i<=a-1){
  16.             if(i==0){
  17.                 M[i][j] = a;
  18.                 if(j!=2*a-2){
  19.                     cout << M[i][j] << " ";
  20.                 }else{
  21.                     cout << M[i][j] << endl;
  22.                 }
  23.             }else if(j<=i-1){
  24.                 M[i][j] = a-j;
  25.  
  26.                 cout << M[i][j] << " ";
  27.             }else if(i<=j and j<=2*a-2-i){
  28.                 M[i][j] = a-i;
  29.  
  30.                 cout << M[i][j] << " ";
  31.             }else{
  32.                 M[i][j] = j-2;
  33.                 if(j!=2*a-2){
  34.                     cout << M[i][j] << " ";
  35.                 }else{
  36.                     cout << M[i][j] << endl;
  37.                 }
  38.             }
  39.         }else{
  40.                 if(i==2*a-2){
  41.                     M[i][j] = a;
  42.                     if(j!=2*a-2){
  43.                         cout << M[i][j] << " ";
  44.                     }else{
  45.                         cout << M[i][j] << endl;
  46.                     }
  47.                 }else if(j<=2*a-2-i){
  48.                     M[i][j] = a-j;
  49.  
  50.                     cout << M[i][j] << " ";
  51.                 }else if(2*a-2-i<j and j<=i){
  52.                     M[i][j] = i+2-a;
  53.  
  54.                     cout << M[i][j] << " ";
  55.                 }else{
  56.                     M[i][j] = j+2-a;
  57.                     if(j!=2*a-2){
  58.                         cout << M[i][j] << " ";
  59.                     }else{
  60.                         cout << M[i][j] << endl;
  61.                     }
  62.                 }
  63.         }
  64.  
  65.         if(j==2*a-2){
  66.             i++;
  67.             j=0;
  68.         }
  69.    }
  70.  
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement