返回列表 發帖
回復 2# 黃宇綸
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;

  3. public class Ch15 {

  4.         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  5.         String tmp;
  6.         int m,n;
  7.         int data[][], res[][];

  8.         Ch15() throws Exception
  9.         {
  10.                 while(br.ready())
  11.                 {
  12.                         tmp=br.readLine();
  13.                         m=Integer.parseInt(tmp.split(" ")[0]);
  14.                         n=Integer.parseInt(tmp.split(" ")[1]);
  15.                         data=new int[m][n];
  16.                         for(int i=0; i<m; i++)
  17.                         {
  18.                                 tmp=br.readLine();
  19.                                 for(int j=0; j<n; j++)
  20.                                         data[i][j]=Integer.parseInt(tmp.split(" ")[j]);
  21.                         }
  22.                         res=new int[n][m];
  23.                         for(int i=0; i<n; i++)
  24.                         {
  25.                                 for(int j=0; j<m; j++)
  26.                                         res[i][j]=data[j][i];
  27.                         }

  28.                         for(int i=0; i<n; i++)
  29.                         {
  30.                                 for(int j=0; j<m; j++)
  31.                                         System.out.print(res[i][j]+" ");
  32.                                 System.out.println();
  33.                         }
  34.                 }
  35.         }

  36.         public static void main(String[] args) throws Exception {
  37.                 new Ch15();
  38.         }
  39. }

  40. /*   
  41.         0 0  <-- 0 0
  42.         0 1  <-- 1 0

  43.         1 0  <-- 0 1
  44.         1 1  <-- 1 1

  45.         2 0  <-- 0 2
  46.         2 1  <-- 1 2
  47. */
複製代碼

TOP

返回列表