JosepRivaille

P28318: Files i columnes

May 21st, 2015
1,958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. //Pre: LLegeix una matriu
  6. //Post: Escriu la consulta de dades corresponent
  7. int main() {
  8.     //Llegir
  9.     int f, c;
  10.     cin >> f >> c;
  11.     int M[f][c];
  12.     for (int i = 0; i < f; ++i) {
  13.         for (int j = 0; j < c; ++j) {
  14.             cin >>  M[i][j];
  15.         }
  16.     }
  17.     //Consultar
  18.     string s;
  19.     while (cin >> s) {
  20.         cout << s << " ";
  21.         if (s == "fila") {
  22.             int x;
  23.             cin >> x;
  24.             cout << x << ":";
  25.             for (int i = 0; i < c; ++i) {
  26.                 cout << " " << M[x-1][i];
  27.             }
  28.         }
  29.         if (s == "columna") {
  30.             int y;
  31.             cin >> y;
  32.             cout << y << ":";
  33.             for (int i = 0; i < f; ++i) {
  34.                 cout << " " << M[i][y-1];
  35.             }
  36.         }
  37.         if (s == "element") {
  38.             int x, y;
  39.             cin >> x >> y;
  40.             cout << x << " " << y << ": " << M[x-1][y-1];
  41.         }
  42.         cout << endl;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment