返回列表 發帖

a015: 矩陣的翻轉

http://zerojudge.tw/ShowProblem?problemid=a015
  1. #include <iostream> //引入函數庫
  2. #include <cstdlib>

  3. using namespace std;
  4. int main(void){


  5.     int a[100][100] = {0};
  6.    
  7.     int b=0,c=0;
  8.    
  9.     a[0][0] = 3;a[0][1] = 1;a[0][2] = 2;
  10.     a[1][0] = 8;a[1][1] = 5;a[1][2] = 4;
  11.    
  12.     b=2 ; c=3;
  13.    
  14.     for(int j=0;j<c;j++){
  15.              for(int i=0;i<b;i++)
  16.              {
  17.                     cout << a[i][j];
  18.                     cout << " ";      
  19.              }
  20.              cout << '\n';     
  21.     }

  22.    
  23.    
  24.    




  25.     system("pause");
  26.     return 0;
  27. }
複製代碼

  1. #include <iostream> //引入函數庫
  2. #include <cstdlib>

  3. using namespace std;
  4. int main(void){

  5.     int b , c;
  6.     int a[100][100] = {0};
  7.     while(cin >> b >> c){
  8.     for(int i = 0; i < b; i++){
  9.     for(int j = 0; j < c; j++){
  10.     cin >> a[i][j];
  11.     }
  12.    
  13. }
  14.    
  15.     for(int j=0;j<c;j++){
  16.              for(int i=0;i<b;i++)
  17.              {
  18.                     cout << a[i][j];
  19.                     cout << " ";      
  20.              }
  21.              cout << '\n';     
  22.     }

  23.     }
  24.    
  25.    




  26.     //system("pause");
  27.     return 0;
  28. }
複製代碼
離離草原上
一歲一枯榮
野火燒不盡
春風吹又生

TOP

  1. /* 第一行會有兩個數字,分別為 列(row)<100 和 行(column)<100,緊接著就是這個矩陣的內容
  2.    直接輸出翻轉後的矩陣 */
  3. #include <iostream>
  4. #include <cstdlib>
  5. using namespace std;
  6. int main(void){
  7.     int row, col;
  8.    
  9.     while (cin >> row >> col){
  10.           int a[row][col];
  11.           int b[col][row];
  12.           for (int i = 0; i < row; i++){
  13.               for (int j = 0; j < col; j++){
  14.                   cin >> a[i][j];   
  15.               }   
  16.           }
  17.           for (int i = 0; i < row; i++){
  18.               for (int j = 0; j < col; j++){
  19.                   b[j][i] = a[i][j];   
  20.               }
  21.           }
  22.           for (int i = 0; i < col; i++){
  23.               for (int j = 0; j < row; j++){
  24.                   cout << b[i][j] << " ";   
  25.               }
  26.               cout << endl;
  27.           }
  28.     }
  29.    
  30.     //system("pause");
  31.     return 0;
  32.    
  33. }
複製代碼
回復 2# b1081081
我是來去無蹤的..

                                ..士豪(Alen)黑輪

TOP

譯仁明明有寫出來,怎麼沒有PO?

TOP

返回列表