图像旋转翻转变换

提交数: 485, 通过率: 58.56%, 平均分: 62.16

题目描述:

给定m行n列的图像各像素点灰度值,对其依次进行一系列操作后,求最终图像。

其中,可能的操作及对应字符有如下四种:

A:顺时针旋转90度;

B:逆时针旋转90度;

C:左右翻转;

D:上下翻转。

输入格式:

第一行包含两个正整数m和n,表示图像的行数和列数,中间用单个空格隔开。1 <= m <= 100, 1 <= n <= 100。
接下来m行,每行n个整数,表示图像中每个像素点的灰度值,相邻两个数之间用单个空格隔开。灰度值范围在0到255之间。
接下来一行,包含由A、B、C、D组成的字符串s,表示需要按顺序执行的操作序列。s的长度在1到100之间。

输出格式:

m'行,每行包含n'个整数,为最终图像各像素点的灰度值。其中m'为最终图像的行数,n'为最终图像的列数。相邻两个整数之间用单个空格隔开。

样例输入:

(双击复制)
2 3
10 0 10
100 100 10
AC

样例输出:

(双击复制)
10 100
0 100
10 10

提示:

完善程序:

#include <bits/stdc++.h>
using namespace std;
int n,m,a[101][101],b[101][101];
string s;
int main() {
	cin >> n >> m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin >> a[i][j];
		}
	}
	cin >> s;
	for(int l=0;l<s.length();l++){
		if(s[l] == 'A'){//顺时针变换
			for(int i=1;i<=n;i++){
				for(int j=1;j<=m;j++){
					____(1)____ = a[i][j];
				}
			}
			____(2)____
		}
		if(s[l] == 'B'){//逆时针变换
			for(int i=1;i<=n;i++){
				for(int j=1;j<=m;j++){
					____(3)____ = a[i][j];
				}
			}
			____(4)____
		}
		if(s[l] == 'C'){//左右翻转
			for(int i=1;i<=n;i++){
				for(int j=1;j<=m;j++){
					____(5)____ = a[i][j];
				}
			}
		}
		if(s[l] == 'D'){//上下翻转
			for(int i=1;i<=n;i++){
				for(int j=1;j<=m;j++){
					____(6)____ = a[i][j];
				}
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				a[i][j] = b[i][j];
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout << a[i][j]<<" ";
		}
		cout <<"\n";
	}
}
时间限制: 1000ms
空间限制: 128MB

来源: openjudge