Advertisement
STANAANDREY

paralele la dp

Aug 29th, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.   int N, m[101][101];
  6.   cin>>N;
  7.   for (int i = 1; i <= N; ++i)
  8.     for (int j = 1; j <= N; ++j)
  9.       cin>>m[i][j];
  10.  
  11.   // parcurgem fiecare element de pe prima linie
  12.   for (int j = N; j >= 1; --j) {
  13.     int linie = 1, coloana = j;
  14.     // parcurgem paralela la diagonala
  15.     while (linie <= N && coloana <= N) {
  16.       cout<<m[linie][coloana]<<' ';
  17.       ++linie;
  18.       ++coloana;
  19.     }
  20.     cout<<'\n';
  21.   }
  22.   // parcurgem fiecare element de pe prima coloana
  23.   for (int i = 2; i <= N; ++i) {
  24.     int linie = i, coloana = 1;
  25.     // parcurgem paralela la diagonala
  26.     while (linie <= N && coloana <= N) {
  27.       cout<<m[linie][coloana]<<' ';
  28.       ++linie;
  29.       ++coloana;
  30.     }
  31.     cout<<'\n';
  32.   }
  33.   return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement