Start: Jun, 26, 2019 08:30:00
2019年度暑期短学期第一天
End: Jun, 26, 2019 11:30:00
Time elapsed:
Time remaining:

Problem_ID: A
Result: Accepted
Time: 7ms
Memory: 1184kB
Author: 2017211909047
In contest: 1273

#include<stdio.h>
using namespace std;
const int maxn = 110;
int a[maxn][maxn] = { 0 };
int b[maxn][maxn] = { 0 };
int main(){
	int T;
	scanf("%d", &T);
	while (T--){
		int n, m, k;
		scanf("%d%d%d", &n, &m, &k);
		k %= 4;
		int t = 0;
		int flag = k % 2;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < m; j++)
				scanf("%d", &a[i][j]);
		}
		while (k--){
			t++;
			if (t % 2 != 0){
				int x = 0;
				int y = 0;
				for (int i = n - 1; i >= 0; i--){
					for (int j = 0; j < m; j++){
						b[j][i] = a[x][y++];
					}
					x++;
					y = 0;
				}
				for (int i = 0; i < m; i++){
					for (int j = 0; j < n; j++)
						a[i][j] = b[i][j];
				}
			}
			else{
				int x = 0;
				int y = 0;
				for (int i = m - 1; i >= 0; i--){
					for (int j = 0; j < n; j++){
						b[j][i] = a[x][y++];
					}
					x++;
					y = 0;
				}
				for (int i = 0; i < n; i++){
					for (int j = 0; j < m; j++)
						a[i][j] = b[i][j];
				}
			}
		}
		if (flag== 0){
			for (int i = 0; i < n; i++){
				for (int j = 0; j < m; j++){
					if (j == 0)
						printf("%d", a[i][j]);
					else
						printf(" %d", a[i][j]);
				}
				printf("\n");
			}
		}
		else{
			for (int i = 0; i < m; i++){
				for (int j = 0; j < n; j++){
					if (j == 0)
						printf("%d", a[i][j]);
					else
						printf(" %d", a[i][j]);
				}
				printf("\n");
			}
		}
		printf("\n");
	}
	return 0;
}