Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <set>
- #include <string.h>
- using namespace std;
- 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+(s.size()-1-mayores));
- s.insert(p);
- }
- return costoTotal;
- }
- int main()
- {
- char l1[] = "Estamos pintando!";
- char l2[] = "ostant!Em inpados";
- cout << procesador(l1, l2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment