fork(2) download
  1. #include<cstdio>
  2. #include<cstring>
  3. #include<string>
  4. #include<cmath>
  5. #include<algorithm>
  6. #include<iostream>
  7. using namespace std;
  8. int tab[101][101];
  9. int main(){
  10. int d,n,m;
  11. scanf("%d",&d);
  12. for(int q=0;q<d;++q){
  13. string g="";
  14. scanf("%d%d\n",&n,&m);
  15. for(int i=0;i<n;++i){
  16. for(int j=0;j<m;++j){
  17. tab[i][j]=0;
  18. }
  19. }
  20. for(int i=0;i<n;++i){
  21. for(int j=0;j<m;++j){
  22. if(j==m-1&&i!=n-1)scanf("%d\n",&tab[i][j]);
  23. else scanf("%d",&tab[i][j]);
  24. }
  25. }
  26. for(int i=0;i<n;++i){
  27. for(int j=0;j<m;++j){
  28. if(i==0){
  29. g+=tab[i][j]+'0';
  30. }
  31. }
  32. }
  33. for(int i=0;i<n;++i){
  34. for(int j=0;j<m;++j){
  35. if(j==m-1&&i!=0){
  36. g+=tab[i][j]+'0';
  37. }
  38. }
  39. }
  40. for(int i=n-1;i>=0;--i){
  41. for(int j=m-1;j>=0;--j){
  42. if(i==n-1&&j!=m-1){
  43. g+=tab[i][j]+'0';
  44. }
  45. }
  46. }
  47. for(int i=0;i<n;++i){
  48. for(int j=0;j<m;++j){
  49. if(j==0&&i!=0&&i!=n-1){
  50. g+=tab[i][j]+'0';
  51. }
  52. }
  53. }
  54. int x=n*2+(m-2)*2;
  55. char dx=g[0];
  56. g.insert(x,1,dx);
  57. g.erase(0,1);
  58. int h=0;
  59. for(int i=0;i<n;++i){
  60. for(int j=0;j<m;++j){
  61. if(i==0){
  62. tab[i][j]=g[h];
  63. h++;
  64. }
  65. }
  66. }
  67. for(int i=0;i<n;++i){
  68. for(int j=0;j<m;++j){
  69. if(j==m-1&&i!=0&&i!=n-1){
  70. tab[i][j]=g[h];
  71. h++;
  72. }
  73. }
  74. }
  75. for(int i=n-1;i>0;--i){
  76. for(int j=m-1;j>0;--j){
  77. if(i==n-1){
  78. tab[i][j]=g[h];
  79. h++;
  80. }
  81. }
  82. }
  83. for(int i=n-1;i>=0;--i){
  84. for(int j=m-1;j>=0;--j){
  85. if(j==0&&i!=0){
  86. tab[i][j]=g[h];
  87. h++;
  88. }
  89. }
  90. }
  91. for(int i=0;i<n;++i){
  92. for(int j=0;j<m;++j){
  93. if(j!=0&&i!=0&&i!=n-1&&j!=m-1){
  94. tab[i][j]+='0';
  95. }
  96. }
  97. }
  98. for(int i=0;i<n;++i){
  99. for(int j=0;j<m;++j){
  100. if(j==m-1&&i!=n-1)printf("%d\n",tab[i][j]-'0');
  101. else printf("%d ",tab[i][j]-'0');
  102. }
  103. }
  104. printf("\n");
  105. }
  106. return 0;
  107. }
Success #stdin #stdout 0s 3508KB
stdin
1
4 5
1 2 3 4 5 
14 7 8 9 6
13 6 5 4 7
12 11 10 9 8
stdout
2 3 4 5 6
1 7 8 9 7
13 6 5 4 8
14 12 11 10 9