Advertisement
vitormartinotti

OBI2022_f2pj_piramide

Aug 8th, 2023 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int MAXN = 100;
  6.  
  7. int p[MAXN][MAXN];
  8.  
  9. int main(){
  10.     int N;
  11.     scanf("%d", &N);
  12.    
  13.     //Para cada camada k da pirâmide, vamos percorrer as linhas i e colunas j da matriz p, com i e j intervalo de k até N-k. Por exemplo, em uma pirâmide de tamanho 5, quando k valer 2 (terceira camada, pois k começa em 0) i e j percorrem as posições 22, 23, 32 e 33.
  14.     for(int k = 0; k < N; k++)
  15.         for(int i = k; i < N - k; i++)
  16.             for(int j = k; j < N - k; j++)
  17.                 p[i][j]++;
  18.  
  19.     for(int i = 0; i < N; i++){
  20.         for(int j = 0; j < N; j++)
  21.             printf("%d ", p[i][j]);
  22.         printf("\n");
  23.     }
  24.  
  25.     return 0;
  26. }
  27.  
Tags: f2pj OBI2022
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement