码迷,mamicode.com
首页 > 编程语言 > 详细

201503-1 图像旋转 Java

时间:2020-02-21 22:36:54      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:read   int()   imp   adl   tin   ade   edr   port   img   

技术图片

import java.util.Scanner;
//得分80,本题最高需要输入100W次,因为nextInt很耗时,导致内存超了
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int a[][] = new int[n][m];
        for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                a[i][j] = sc.nextInt();
            }
        }
        int count = 0;
        for(int j=m-1;j>=0;j--) {
            for(int i=0;i<n;i++) {
                System.out.print(a[i][j] + " ");
                count++;
                if(count % n == 0) {
                    System.out.println();
                }
            }
        }
        sc.close();
    }

}

下面还有

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
//100分,用BufferedReader
public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
        String str;
        String [] temp;
        
        str = buff.readLine();
        temp = str.split(" ");
        int n = Integer.parseInt(temp[0]);
        int m = Integer.parseInt(temp[1]);
        int a[][] = new int[n][m];
        for(int i=0;i<n;i++) {
            str = buff.readLine();
            temp = str.split(" ");
            for(int j=0;j<m;j++) {
                a[i][j] = Integer.parseInt(temp[j]);
            }
        }
        for(int j=m-1;j>=0;j--) {
            for(int i=0;i<n;i++) {
                System.out.print(a[i][j] + " ");
                if(i == n-1) {
                    System.out.println();
                }
            }
        }
        sc.close();
    }

}

201503-1 图像旋转 Java

标签:read   int()   imp   adl   tin   ade   edr   port   img   

原文地址:https://www.cnblogs.com/yu-jiawei/p/12343204.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!