GastonFontenla

Untitled

May 31st, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. long long procesador(char texto[], char prueba[])
  2. {
  3.     long long costoTotal = 0;
  4.     int n = strlen(texto);
  5.  
  6.     set<int> s;
  7.     queue <int> letras[130];
  8.  
  9.     for(int i=0; i<n; i++)
  10.         letras[prueba[i]].push(i);
  11.  
  12.     for(int i=0; i<n; i++)
  13.     {
  14.         int p = letras[texto[i]].front();
  15.         letras[texto[i]].pop();
  16.  
  17.         ///Buscar cuántos mayores a P tengo en el set
  18.         int mayores = distance(s.begin(), s.upper_bound(p));
  19.         costoTotal += (p-i-mayores+s.size());
  20.  
  21.         s.insert(p);
  22.     }
  23.  
  24.     return costoTotal;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment