九度OJ-题目1171:C翻转-10计院上机C
2017-03-21 13:21
281 查看
题目描述:
首先输入一个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
首先输入一个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; }
相关文章推荐
- 【九度OJ】题目1171:C翻转 解题报告
- 九度OJ-题目1169:比较奇偶数个数-10计院上机A
- 九度OJ-题目1170:找最小数-10计院上机B
- 九度OJ-题目1172:哈夫曼树-10计院上机D
- 九度OJ-题目1175:打牌-10网研上机C
- 九度OJ 题目1171:C翻转
- 九度OJ-题目1176:树查找-10网研上机D
- 九度 oj 题目1171:C翻转
- 九度 oj 题目1208:10进制 VS 2进制
- 九度OJ 1171:C翻转 (矩阵计算)
- 九度OJ-题目1361:翻转单词顺序
- 九度OJ 1171:C翻转 (矩阵计算)
- 九度OJ-题目1173:查找-10网研上机A
- 【九度OJ】题目1208:10进制 VS 2进制 解题报告
- 【九度OJ】题目1195:最长&最短文本 解题报告
- 【九度OJ】题目1197:奇偶校验 解题报告
- 【九度OJ】题目1073:杨辉三角形 解题报告
- 九度OJ-题目1035 找出直系亲属
- 九度OJ:题目1015 还是A+B
- 九度OJ题目1078:二叉树遍历