11:图像旋转
-
总时间限制:
- 1000ms 内存限制:
- 65536kB
-
描述
-
输入一个n行m列的黑白图像,将它顺时针旋转90度后输出。
输入 - 第一行包含两个整数n和m,表示图像包含像素点的行数和列数。1 <= n <= 100,1 <= m <= 100。
接下来n行,每行m个整数,表示图像的每个像素点灰度。相邻两个整数之间用单个空格隔开,每个元素均在0~255之间。
输出 - m行,每行n个整数,为顺时针旋转90度后的图像。相邻两个整数之间用单个空格隔开。 样例输入
-
3 3 1 2 3 4 5 6 7 8 9
样例输出 -
7 4 1 8 5 2 9 6 3
分析:考察 矩阵的翻转。
#include <stdio.h>
#include <iostream>
#include <stack>
#include <string.h>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
using namespace std;
typedef long long LL;
#define MAX 10001
int a[MAX][MAX];
int b[MAX][MAX];
int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int n, m;
cin >> n >> m;
int k = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
for(int i = 1; i <= m; i++) {
int k = 0;
for(int j = 1; j <= n; j++) {
b[i][j] = a[n - k][i];
k++;
}
}
for(int i = 1; i <= m; i++) {
for(int j = 1; j <= n; j++) {
if(j != 1) {
cout << " " << b[i][j] ;
}else {
cout << b[i][j] ;
}
}
cout << endl;
}
return 0;
}