当前位置:网站首页>矩阵翻转(数组模拟)
矩阵翻转(数组模拟)
2022-07-04 17:59:00 【相思明月楼】
问题
晓萌最近在做一个翻转图片的应用,你可能也知道,图片其实是由一个个的点组成的。于是,晓萌想先做一个可以翻转矩阵的程序,来解决他问题的核心部分。
输入格式
输入第一行包括由空格分开的整数 M,N,T(0 < N,M < 200)M,N,T(0<N,M<200),TT 的值为 00 或 11。其中 MM 和 NN 分别表示待处理矩阵的行数与列数,TT 为 00 时表示左右翻转,为 11 时表示上下翻转。
之后的 MM 行,每行包括由空格分隔的 NN 个整数,依次为输入矩阵的每一行的数据。
输出格式
输出包括 MM 行 NN 列,每个数字之间用一个空格分隔,每一行行末均有一个空格,表示的是按照要求翻转后的矩阵。
样例输入
4 4 1 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
样例输出
3 4 5 6 9 0 1 2 5 6 7 8 1 2 3 4
直接用数组模拟。
#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 210;
int mp[MAXN][MAXN];
int main() {
int m, n, t;
scanf("%d %d %d", &m, &n, &t);
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) {
scanf("%d", &mp[i][j]);
}
}
if(t == 1) {
for(int i = m - 1; i >= 0; i--) {
for(int j = 0; j < n; j++) {
printf("%d ", mp[i][j]);
}
printf("\n");
}
} else {
for(int i = 0; i < m; i++) {
for(int j = n - 1; j >= 0; j--) {
printf("%d ", mp[i][j]);
}
printf("\n");
}
}
return 0;
}
边栏推荐
- 更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
- LeetCode 赎金信 C#解答
- 联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
- 英特尔集成光电研究最新进展推动共封装光学和光互连技术进步
- FPGA timing constraint sharing 01_ Brief description of the four steps
- Opencv functions and methods related to binary threshold processing are summarized for comparison and use
- PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
- QT realizes interface sliding switching effect
- Detailed explanation of the binary processing function threshold() of opencv
- 2022健康展,北京健博会,中国健康展,大健康展11月13日
猜你喜欢
随机推荐
联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
node_exporter部署
Lm10 cosine wave homeopathic grid strategy
1007 Maximum Subsequence Sum(25 分)(PAT甲级)
Using FTP
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
HDU 1372 & POJ 2243 Knight Moves(广度优先搜索)
Leetcode fizzbuzz C # answer
千万不要只学 Oracle、MySQL!
PolyFit软件介绍
IBM WebSphere MQ retrieving messages
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
从实时应用角度谈通信总线仲裁机制和网络流控
Unity编辑器扩展C#遍历文件夹以及子目录下的所有图片
Shell 编程核心技术《三》
2022健康展,北京健博会,中国健康展,大健康展11月13日
升级智能开关,“零火版”、“单火”接线方式差异有多大?
启牛开的证券账户安全吗?
牛客小白月赛7 谁是神箭手
Detailed explanation of the binary processing function threshold() of opencv