fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int t, a, b, *tab, x = 0, h;
  8.  
  9. cin >> t;
  10.  
  11. for (int i = 0; i < t; i++)
  12. {
  13. cin >> a >> b;
  14. tab = new int[a*b];
  15.  
  16. for (int j = 0; j < a; j++)
  17. {
  18. for (int p = 0; p < b; p++)
  19. {
  20. cin >> tab[x];
  21. x++;
  22. }
  23. }
  24.  
  25.  
  26. for (int j = 1; j < b; j++)
  27. {
  28. cout << tab[j] << " ";
  29. }
  30. cout << tab[(b + b) - 1] << endl;
  31.  
  32. h = b;
  33.  
  34. for (int j = 0; j < a - 2; j++)
  35. {
  36. cout << tab[h - h] << " ";
  37. for (int p = h + 1; p < h + b - 1; p++)
  38. {
  39. cout << tab[p] << " ";
  40. }
  41. cout << tab[h + b + b - 1] << endl;
  42. h += b;
  43. }
  44.  
  45. cout << tab[h - b] << " ";
  46.  
  47. for (int j = h; j < (a * b) - 1; j++)
  48. {
  49. cout << tab[j] << " ";
  50. }
  51. cout << endl;
  52.  
  53. delete[] tab;
  54. x = 0;
  55. }
  56.  
  57. return 0;
  58. }
Success #stdin #stdout 0s 3464KB
stdin
1
3 5
1 2 3 4 5 
6 7 8 9 0
1 2 3 4 5
stdout
2 3 4 5 0
1 7 8 9 5
6 1 2 3 4