http://acm.zzuli.edu.cn/problem.php?id=1733
转转转~
旋转图像
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 297 Solved: 136
Description
Input
Output
Sample Input
2
2 3
111
000
90
3 3
111
101
111
180
Sample Output
01
01
01
111
101
111
HINT
#include<stdio.h>
#include<string.h>
#define maxn 55
int ch[maxn][maxn];
void fanzhuan(int n, int m) // 写一个翻转90度的函数,多次利用
{
int i, j;
int hc[maxn][maxn] = {{0}};
for(i = 0; i < n; i++)
{
for(j = 0; j < m; j++)
hc[i][j] = ch[i][j];
}
memset(ch, 0, sizeof(ch));
for(i = 0; i < n; i++)
{
for(j = 0; j < m; j++)
ch[j][n-1-i] = hc[i][j]; // 旋转坐标变化
}
}
int main()
{
int i, j, t, n, m, angle, a, b, temp;
scanf("%d", &t);
while(t--)
{
scanf("%d%d", &n, &m);
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
scanf("%d", &ch[i][j]);
scanf("%d", &angle);
a = angle % 180; // 判断行列是否变化
b = angle % 360;
if(b == 90)
fanzhuan(n, m);
if(b == 180)
{
fanzhuan(n, m);
fanzhuan(m, n);
}
if(b == 270)
{
fanzhuan(n, m);
fanzhuan(m, n);
fanzhuan(n, m);
}
if(a == 90)
{
temp = m, n = n, n = temp;
}
for(i = 0; i < n; i++)
{
for(j = 0; j < m; j++)
printf("%d\n", ch[i][j]);
}
}
return 0;
}