csansoon

P8.01 P28318 Rows and columns

Nov 28th, 2018
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. typedef vector<vector<int> > matrix;
  6.  
  7. int main() {
  8.     int x,y,n,n2;
  9.     cin>>x>>y;
  10.     matrix m(x,vector <int> (y,0));
  11.     for (int i=0;i<x;++i) {
  12.         for (int j=0; j<y;++j) {
  13.             cin>>m[i][j];
  14.         }
  15.     }
  16.     string s;
  17.     while (cin>>s) {
  18.         if (s=="row") {
  19.             cin>>n;
  20.             cout<<"row "<<n<<":";
  21.             for (int i=0; i<y; ++i) cout<<" "<<m[n-1][i];
  22.             cout<<endl;
  23.         }
  24.         else if (s=="column") {
  25.             cin>>n;
  26.             cout<<"column "<<n<<":";
  27.             for (int i=0; i<x; ++i) cout<<" "<<m[i][n-1];
  28.             cout<<endl;
  29.         }
  30.         else if (s=="element") {
  31.             cin>>n>>n2;
  32.             cout<<"element "<<n<<" "<<n2<<": "<<m[n-1][n2-1]<<endl;
  33.         }
  34.     }
  35. }
  36.  
  37. // (c) Carlos Sansón (Best pro1 delegate ever for sure) @csansoon
Advertisement
Add Comment
Please, Sign In to add comment