九度OJ-题目1171:C翻转-10计院上机C
来源:互联网 发布:java安装失败1335 编辑:程序博客网 时间:2024/05/22 04:35
题目描述:
首先输入一个5 * 5的数组,然后输入一行,这一行有四个数,前两个代表操作类型,后两个数x y代表需操作数据为以x y为左上角的那几个数据。
操作类型有四种:
1 2 表示:90度,顺时针,翻转4个数
1 3 表示:90度,顺时针,翻转9个数
2 2 表示:90度,逆时针,翻转4个数
2 3 表示:90度,逆时针,翻转9个数
输入:
输入有多组数据。
每组输入一个5 * 5的数组,然后输入一行,这一行有四个数,前两个代表操作类型,后两个数x y代表需操作数据为以x y为左上角的那几个数据。
输出:
输出翻转后的数组。
样例输入:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
1 3 1 1
样例输出:
11 6 1 4 5
12 7 2 9 10
13 8 3 14 15
16 17 18 19 20
21 22 23 24 25
#include <iostream>#include <cstdio> using namespace std;int buf[5][5];void swap(int &a,int &b){ int temp=a; a=b; b=temp;} void clockWise2(int x,int y){ int temp; temp=buf[x][y]; swap(temp,buf[x][y+1]); swap(temp,buf[x+1][y+1]); swap(temp,buf[x+1][y]); swap(temp,buf[x][y]);}void clockWise3(int x,int y){ int temp; for (int i=0;i<2;i++){ temp=buf[x][y]; swap(temp,buf[x][y+1]); swap(temp,buf[x][y+2]); swap(temp,buf[x+1][y+2]); swap(temp,buf[x+2][y+2]); swap(temp,buf[x+2][y+1]); swap(temp,buf[x+2][y]); swap(temp,buf[x+1][y]); swap(temp,buf[x][y]); }}void antiClock2(int x,int y){ for (int i=0;i<3;i++){ clockWise2(x,y); }}void antiClock3(int x,int y){ for (int i=0;i<3;i++){ clockWise3(x,y); }}int main(){ int operation[4]; bool firstCase; while (scanf("%d",&buf[0][0])!=EOF){ //input for (int i=0;i<5;i++){ for (int j=0;j<5;j++){ if (i==0&&j==0) continue; scanf("%d",&buf[i][j]); } } for (int i=0;i<4;i++){ scanf("%d",&operation[i]);/*bug*/ } operation[2]--;/*bug*/ operation[3]--; //initiate //operate switch (operation[0]){ case 1: if (operation[1]==2) clockWise2(operation[2],operation[3]); else if (operation[1]=3) clockWise3(operation[2],operation[3]); break; case 2: if (operation[1]==2) antiClock2(operation[2],operation[3]); else if (operation[1]=3) antiClock3(operation[2],operation[3]); break; } //output for (int i=0;i<5;i++){ firstCase=true; for (int j=0;j<5;j++){ if (firstCase) firstCase=false; else printf(" "); printf("%d",buf[i][j]); } printf("\n"); } } return true;}
0 0
- 九度OJ-题目1171:C翻转-10计院上机C
- 九度OJ 题目1171:C翻转
- 九度 oj 题目1171:C翻转
- 【九度OJ】题目1171:C翻转 解题报告
- 九度OJ-题目1169:比较奇偶数个数-10计院上机A
- 九度OJ-题目1170:找最小数-10计院上机B
- 九度OJ-题目1172:哈夫曼树-10计院上机D
- 九度OJ-题目1175:打牌-10网研上机C
- 九度OJ 1171:C翻转 (矩阵计算)
- 北邮OJ-97. 二叉排序树-12计院上机C
- 北邮OJ-278. 图像识别-14计院上机C
- 北邮OJ-105. 寻找宝藏-11计院上机C
- 题目1171:C翻转
- 题目1171:C翻转
- 题目1171:C翻转
- 题目1171:C翻转
- 北邮OJ-93. 中序遍历序列-13计院上机C
- 北邮OJ-272. 网络的核-14计院上机(第二套)C
- instanceof
- Android 判断设备 是否使用代理上网
- 阿里云大数据三次技术突围:Greenplum、Hadoop和“飞天”
- Linux下gcc编译生成动态链接库*.so文件并调用它
- javaTestHTML
- 九度OJ-题目1171:C翻转-10计院上机C
- Find Coins (25)
- 测试岗位趋势浅见
- C/C++判断操作系统(Win10,Win8.1WinServer等等)-完整源码及思路
- Minimum Depth of Binary Tree问题及解法
- attr()与prop()
- 按钮返回并刷新页面
- Ubuntu 下面访问其它 samba 服务器
- shell脚本实现网络连接的检测