f0702.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:

C#编程

开发平台:

Visual C++

  1. //=====================================
  2. // f0702.cpp
  3. // 消去全局数据
  4. //=====================================
  5. #include<iostream>
  6. #include<iomanip>
  7. #include<fstream>
  8. #include<vector>
  9. using namespace std;
  10. //-------------------------------------
  11. typedef vector<vector<int> > Mat;
  12. Mat input();
  13. Mat transpose(const Mat& a);
  14. void print(const Mat& a);
  15. //-------------------------------------
  16. int main(){
  17.   print(transpose(input()));
  18. }//------------------------------------
  19. Mat input(){
  20.   ifstream in("a.txt");
  21.   int row, col;
  22.   in>>row>>col;
  23.   Mat a(row, vector<int>(col));
  24.   for(int i=0; i<row; ++i)
  25.   for(int j=0; j<col; ++j)
  26.     in>>a[i][j];
  27.   return a;
  28. }//------------------------------------
  29. Mat transpose(const Mat& a){
  30.   Mat b(a[0].size(), vector<int>(a.size()));
  31.   for(int i=0; i<a.size(); ++i)
  32.   for(int j=0; j<a[0].size(); ++j)
  33.     b[j][i] = a[i][j];
  34.   return b;
  35. }//------------------------------------
  36. void print(const Mat& a){
  37.   for(int i=0; i<a.size(); ++i){
  38.     for(int j=0; j<a[0].size(); ++j)
  39.       cout<<setw(4)<<a[i][j];
  40.     cout<<endl;
  41.   }
  42. }//====================================
  43.