JosepRivaille

P42595: Control C401B

May 23rd, 2015
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5.  
  6. typedef vector< vector<int> > Matriu;
  7.  
  8. void read_matrix(Matriu& mat) {
  9.     int f = mat.size();
  10.     int c = mat[0].size();
  11.     for (int i = 0; i < f; ++i) {
  12.         for (int j = 0; j < c; ++j) {
  13.             cin >> mat[i][j];
  14.         }
  15.     }
  16. }
  17.  
  18. void min_max(Matriu& mat, int& minim, int& maxim) {
  19.     int f = mat.size();
  20.     int c = mat[0].size();
  21.     for (int i = 0; i < f; ++i) {
  22.         for (int j = 0; j < c; ++j) {
  23.             if (mat[i][j] > maxim) maxim = mat[i][j];
  24.             if (mat[i][j] < minim) minim = mat[i][j];
  25.         }
  26.     }
  27. }
  28.  
  29. int main() {
  30.     int f, c;
  31.     int dif_max = 0;
  32.     int count = 0;
  33.     int primer = 1;
  34.     while (cin >> f >> c) {
  35.         Matriu mat(f, vector<int>(c));
  36.         read_matrix(mat);
  37.         ++count;
  38.         int min = mat[0][0];
  39.         int max = mat[0][0];
  40.         min_max(mat, min, max);
  41.         int dif = max - min;
  42.         if (dif > dif_max) {
  43.             dif_max = dif;
  44.             primer = count;
  45.         }
  46.     }
  47.     cout << "la diferencia maxima es " << dif_max << endl;
  48.     cout << "la primera matriu amb aquesta diferencia es la " << primer << endl;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment