JosepRivaille

X47203: Escala consonant de paraules

May 28th, 2015
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5.  
  6.  
  7. struct Paraula {
  8.     string contingut;   //La paraula
  9.     int consonants;     //Nombre d'aparicions de consonants
  10. };
  11.  
  12.  
  13. typedef vector< vector<Paraula> > MatParaules;
  14.  
  15.  
  16. void read_matrix(MatParaules& M) {
  17.     int f = M.size();
  18.     int c = M[0].size();
  19.     for (int i = 0; i < f; ++i) {
  20.         for (int j = 0; j < c; ++j) {
  21.             cin >> M[i][j].contingut;
  22.             int tam = M[i][j].contingut.size();
  23.             int consonants = 0;
  24.             for (int k = 0; k < tam; ++k) {
  25.                 if (M[i][j].contingut[k] != 'A') {
  26.                     if (M[i][j].contingut[k] != 'E') {
  27.                         if (M[i][j].contingut[k] != 'I') {
  28.                             if (M[i][j].contingut[k] != 'O') {
  29.                                 if (M[i][j].contingut[k] != 'U') ++consonants;
  30.                             }
  31.                         }
  32.                     }
  33.                 }
  34.             }
  35.             M[i][j].consonants = consonants;
  36.         }
  37.     }
  38. }
  39.  
  40. void search_cons(const MatParaules& M, int k) {
  41.     int f = M.size();
  42.     int c = M[0].size();
  43.     int x, y;
  44.     bool trobat = false;
  45.     for (int i = 0; i <= f-k && not trobat; ++i) {
  46.         for (int j = 0; j <= c-k && not trobat; ++j) {
  47.             int comp = 0;
  48.             bool error = false;
  49.             for (int aux = 0; aux < k && not error; ++aux) {
  50.                 if (M[i+aux][j+aux].consonants > comp) comp = M[i+aux][j+aux].consonants;
  51.                 else error = true;
  52.             }
  53.             if (not error) {
  54.                 trobat = true;
  55.                 x = i;
  56.                 y = j;
  57.             }
  58.         }
  59.     }
  60.     if (not trobat) cout << "-1 -1" << endl;
  61.     else {
  62.         cout << x << " " << y << " " << M[x][y].contingut << endl;
  63.     }
  64. }
  65.  
  66. int main() {
  67.     int f, c, k;
  68.     cin >> f >> c >> k;
  69.     MatParaules M(f, vector<Paraula>(c));
  70.     read_matrix(M);
  71.     search_cons(M, k);
  72. }
  73.  
  74. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment