fork(4) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 100;
  5.  
  6. const int MAX_COLUMNS = 20;
  7.  
  8. const int FOUR_LINES = 4;
  9.  
  10. const int ONE = 1, TWO = 2, THREE = 3, FOUR = 4;
  11.  
  12. int main() {
  13. int n, mtx[MAX_SIZE + 1][MAX_SIZE + 1];
  14. cin >> n;
  15. for (int i = 1; i <= n; ++i) {
  16. for (int j = 1; j <= n; ++j) {
  17. cin >> mtx[i][j];
  18. }
  19. }
  20. int m[FOUR_LINES + 1][MAX_COLUMNS];
  21. int columnForOne = 1, columnForTwo = 1, columnForThree = 1, columnForFour = 1;
  22. for (int line = 1; line <= n; ++line) {
  23. for (int column = 1; column <= n; ++column) {
  24. if ((line != column) && (line + column != n + 1) && (line < column) && (line + column <= n)) {
  25. m[ONE][columnForOne] = mtx[line][column];
  26. ++columnForOne;
  27. }
  28. else if ((line != column) && (line + column != n + 1) && (line > column) && (line + column <= n)) {
  29. m[TWO][columnForTwo] = mtx[line][column];
  30. ++columnForTwo;
  31. }
  32. else if ((line != column) && (line + column != n + 1) && (line > column) && (line + column > n + 1)) {
  33. m[THREE][columnForThree] = mtx[line][column];
  34. ++columnForThree;
  35. }
  36. else if ((line != column) && (line + column != n + 1) && (line < column) && (line + column > n + 1)) {
  37. m[FOUR][columnForFour] = mtx[line][column];
  38. ++columnForFour;
  39. }
  40. }
  41. }
  42. int columnRank;
  43. if (n % 2 == 0){
  44. columnRank = (n * n - (n + n)) / 4;
  45. } else {
  46. columnRank = (n * n - (n + n - 1)) / 4;
  47. }
  48. for (int i = 1; i <= FOUR; ++i) {
  49. for (int j = 1; j <= columnRank; ++j) {
  50. cout << m[i][j] << " ";
  51. }
  52. cout << "\n";
  53. }
  54. return 0;
  55. }
Success #stdin #stdout 0.01s 5520KB
stdin
5
50 55 75 41 10
111 333 44 8 0
1 2 3 4 5
23 12 1987 91 20
9999 8000 7001 5005 1001
stdout
55 75 41 44 
111 1 2 23 
1987 8000 7001 5005 
0 4 5 20