返回列表 發帖
本帖最後由 黃宇綸 於 2020-11-23 19:22 編輯

// A015
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. public class Ch01 {
  5.         static int n,m;
  6.         static int a[][];
  7.         Ch01() throws IOException
  8.         {
  9.                 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  10.                 String t[];
  11.                 t=br.readLine().split(" ");
  12.                 n=Integer.parseInt(t[0]);
  13.                 m=Integer.parseInt(t[1]);
  14.                 a=new int[n][m];
  15.                 String t1[]=new String[n];
  16.                 for(int i=0;i<n;i++)
  17.                         t1[i]=br.readLine();
  18.                 for(int i=0;i<n;i++)
  19.                         for(int j=0;j<m;j++)
  20.                                 a[i][j]=Integer.parseInt(t1[i].split(" ")[j]);
  21.         int tm[][]=new int[n][m];
  22.                 for(int i=0;i<n;i++)
  23.                         for(int j=0;j<m;j++)
  24.                                 tm[i][j]=a[i][j];
  25.                 a=new int[m][n];
  26.                 for(int i=0;i<m;i++)
  27.                         for(int j=0;j<n;j++)
  28.                                 a[i][j]=tm[j][i];
  29.         for(int i=0;i<m;i++)
  30.         {
  31.                         for(int j=0;j<n;j++)
  32.                                 System.out.print(a[i][j]+" ");
  33.                         System.out.println();
  34.         }
  35.         }
  36.         public static void main(String[] args) throws IOException {
  37.                 new Ch01();
  38.         }
  39. }
複製代碼
Allen

TOP

返回列表