Advertisement
danixan

Problem X47228_ca: Subparaula més llarga d'una sola lletra

Mar 6th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1.         #include "utils.PRO2"
  2.         #include "Palabra.hh"
  3.    
  4.         int consultar (const Palabra& p) {
  5.             int sub = 1;
  6.             int max = sub;
  7.             if (p.long_pal() > 1) {
  8.             for (int i = 2; i <= p.long_pal(); ++i) {
  9.                 if (p.consultar_letra(i-1) == p.consultar_letra(i)) ++sub;
  10.                 else {
  11.                     if (max < sub) max = sub;
  12.                     sub = 1;
  13.                 }
  14.             }
  15.         }
  16.             if (max < sub) max = sub;
  17.             return max;
  18.         }
  19.        
  20.         int main() {
  21.           Palabra p;
  22.           p.leer('.');
  23.           if (p.long_pal() > 0) cout << consultar(p);
  24.           else cout << "0";
  25.           cout << endl;
  26.           }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement