Result: Accepted
Time: 6ms
Memory: 1128kB
#include<stdio.h>
int main(void){
int t,m,n,a[200][200],k,i,j,p,q,r,s;
scanf("%d",&t);
while(t--){
scanf("%d %d %d",&n,&m,&k);
for(i=0;i<n;i++){
for(j=0;j<m;j++){
scanf("%d",&a[i][j]);
}
}
if(n!=m&&(k%4==1||k%4==3)){
for(r=0;r<m;r++){
for(s=0;s<n;s++){
if(k%4==1)
printf("%d",a[n-1-s][r]);
if(k%4==3)
printf("%d",a[s][m-1-r]);
if(s<n-1)
printf(" ");
}
printf("\n");
}
printf("\n");
}
else{
for(p=0;p<n;p++){
for(q=0;q<m;q++){
if(k%4==0)
printf("%d",a[p][q]);
if(k%4==1)
printf("%d" ,a[n-q-1][p]);
if(k%4==2)
printf("%d",a[n-p-1][m-q-1]);
if(k%4==3)
printf("%d" ,a[q][m-p-1]);
if(q<m-1)
printf(" ");
}
printf("\n");
}
printf("\n");
}
}
}