矩阵翻转
Time Limit:1000MS Memory Limit:65536K
Total Submit:171 Accepted:78
Description
大部分图像处理程序(比如photoshop)都有图像翻转功能,可以把图像按90度、180度、270度进行翻转。通常一幅图像可以用一个矩阵来描述。你的任务就是将输入的图像矩阵按指定的角度进行翻转。
Input
由若干行组成。第一行是一个整数,指明了图像的宽和高;第二行是一个整数,表示将要执行的操作:1表示翻转90度,2表示翻转180度,3表示翻转270度;从第三行开始,就是具体矩阵数据。
Output
翻转后的矩阵,第行的数据之间用一个空格隔开。
Sample Input
3
1
1 2 3
4 5 6
7 8 9
Sample Output
3 6 9
2 5 8
1 4 7
Hint
(矩阵的长和宽在[3,100]之间,且所有的数据都为[1,10000]之间的自然数)
Source
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AK1049 {
class Program {
static int[,] a = new int[101, 101];
static void f(int n)//翻转90度
{
for (int j = n - 1; j >= 0; j--) {
for (int i = 0; i < n; i++) {
Console.Write("{0} ", a[i, j]);
}
Console.WriteLine();
}
}
static void g(int n)//翻转180度
{
for (int i = n - 1; i >= 0; i--) {
for (int j = n - 1; j >= 0; j--) {
Console.Write("{0} ", a[i, j]);
}
Console.WriteLine();
}
}
static void h(int n)//翻转270度
{
for (int i = 0; i < n; i++) {
for (int j = n - 1; j >= 0; j--) {
Console.Write("{0} ", a[j, i]);
}
Console.WriteLine();
}
}
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int m = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++) {
string[] s = Console.ReadLine().Split();
for (int j = 0; j < n; j++) {
a[i, j] = int.Parse(s[j]);
}
}
if (m == 1)
f(n);
if (m == 2)
g(n);
if (m == 3)
h(n);
//Console.ReadLine();
}
}
}