⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 f0701.cpp

📁 it is a usefull thing
💻 CPP
字号:
//=====================================
// f0701.cpp
// 矩阵转置
//=====================================
#include<iostream>
#include<iomanip>
#include<fstream>
#include<vector>
using namespace std;
//-------------------------------------
vector<vector<int> > a;   // global variable
void input();
void transpose();
void print();
//-------------------------------------
int main(){
  input();
  transpose();
  print();
}//------------------------------------
void input(){
  ifstream in("a.txt");
  int row, col;
  in>>row>>col;
  a.resize(row, vector<int>(col));
  for(int i=0; i<row; ++i)
  for(int j=0; j<col; ++j)
    in>>a[i][j];
}//------------------------------------
void transpose(){
  vector<vector<int> > b(a[0].size(), vector<int>(a.size()));
  for(int i=0; i<a.size(); ++i)
  for(int j=0; j<a[0].size(); ++j)
    b[j][i] = a[i][j];
  a = b;
}//------------------------------------
void print(){
  for(int i=0; i<a.size(); ++i){
    for(int j=0; j<a[0].size(); ++j)
      cout<<setw(4)<<a[i][j];
    cout<<endl;
  }
}//====================================

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -