fork download
  1. //Bai 14
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. #define el "\n"
  6. #define ll long long
  7. #define ull unsigned long long
  8. #define se second
  9. #define fi first
  10. #define be begin()
  11. #define en end()
  12. #define Faster cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
  13. int n;
  14. void Run()
  15. {
  16. cin >> n;
  17. int a[n][n];
  18. int dem = 1;
  19. for(int i = 0; i < n; i++)
  20. {
  21. if(i % 2 == 0)
  22. {
  23. for(int j = 0; j < n; j++) a[i][j] = dem++ ;
  24. }
  25. else
  26. {
  27. dem += n - 1;
  28. for(int j = 0; j < n; j++) a[i][j] = dem--;
  29. dem += n + 1;
  30. }
  31. }
  32. for(int i = 0 ; i < n; i++)
  33. {
  34. for(int j = 0; j < n; j++)
  35. {
  36. cout << a[j][i] << " ";
  37. }
  38. cout << el;
  39. }
  40. }
  41. int main()
  42. {
  43. Faster;
  44. Run();
  45. return 0;
  46. }
  47.  
  48.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty