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

📄 f0702.cpp

📁 《C++程序设计教程(第二版)》源代码 源代码中包括运行所需的数据文件,它的格式是*.txt,还有*.in和*.out的。头文件格式是*.h
💻 CPP
字号:
//=====================================
// f0702.cpp
// 消去全局数据
//=====================================
#include<iostream>
#include<iomanip>
#include<fstream>
#include<vector>
using namespace std;
//-------------------------------------
typedef vector<vector<int> > Mat;
Mat input();
Mat transpose(const Mat& a);
void print(const Mat& a);
//-------------------------------------
int main(){
  print(transpose(input()));
}//------------------------------------
Mat input(){
  ifstream in("a.txt");
  int row, col;
  in>>row>>col;
  Mat a(row, vector<int>(col));
  for(int i=0; i<row; ++i)
  for(int j=0; j<col; ++j)
    in>>a[i][j];
  return a;
}//------------------------------------
Mat transpose(const Mat& a){
  Mat 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];
  return b;
}//------------------------------------
void print(const Mat& a){
  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 + -