CCF系列之图像旋转(201503-1)

试题编号: 201503-1
时间限制: 5.0s 
内存限制: 256.0MB

问题描述
  旋转是图像处理的基本操作,在这个问题中,你需要将一个图像逆时针旋转90度。
  计算机中的图像表示可以用一个矩阵来表示,为了旋转一个图像,只需要将对应的矩阵旋转即可。
输入格式
  输入的第一行包含两个整数n, m,分别表示图像矩阵的行数和列数。
  接下来n行每行包含m个整数,表示输入的图像。
输出格式
  输出m行,每行包含n个整数,表示原始矩阵逆时针旋转90度后的矩阵。
样例输入
2 3
1 5 3
3 2 4
样例输出
3 4
5 2
1 3
评测用例规模与约定
  1 ≤ n, m ≤ 1,000,矩阵中的数都是不超过1000的非负整数。
 
代码(java):
  
 1 package ccf_test2015_03;
 2 
 3 import java.util.Scanner;
 4 
 5 public class PictureXuanzhuan {
 6 
 7     public static void main(String[] args) {
 8         
 9         Scanner input = new Scanner(System.in);
10         
11         int row = input.nextInt();
12         
13         int col = input.nextInt();
14         
15         input.nextLine();
16         
17         int [][]array = new int [row][col];
18         
19         for(int i = 0;i < row;i++){
20             
21             for(int j = 0;j < col;j++){
22                 
23                 array[i][j] = input.nextInt();
24             }
25             input.nextLine();
26         }
27         for(int j = col-1;j>=0;j--){
28             
29             for(int i = 0;i<row;i++){
30                 
31                 System.out.print(array[i][j] + " ");
32             }
33             System.out.println();
34         }
35           
36     }
37 
38 }
View Code

运行结果:

  

原文地址:https://www.cnblogs.com/haimishasha/p/5331208.html