Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long long procesador(char texto[], char prueba[])
- {
- long long costoTotal = 0;
- int n = strlen(texto);
- set<int> s;
- queue <int> letras[130];
- for(int i=0; i<n; i++)
- letras[prueba[i]].push(i);
- for(int i=0; i<n; i++)
- {
- int p = letras[texto[i]].front();
- letras[texto[i]].pop();
- ///Buscar cuántos mayores a P tengo en el set
- int mayores = distance(s.begin(), s.upper_bound(p));
- costoTotal += (p-i-mayores+s.size());
- s.insert(p);
- }
- return costoTotal;
- }
Advertisement
Add Comment
Please, Sign In to add comment