GastonFontenla

OIA

May 30th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <set>
  4. #include <string.h>
  5.  
  6. using namespace std;
  7.  
  8. long long procesador(char texto[], char prueba[])
  9. {
  10.     long long costoTotal = 0;
  11.     int n = strlen(texto);
  12.  
  13.     set<int> s;
  14.     queue <int> letras[130];
  15.  
  16.     for(int i=0; i<n; i++)
  17.         letras[prueba[i]].push(i);
  18.  
  19.     for(int i=0; i<n; i++)
  20.     {
  21.         int p = letras[texto[i]].front();
  22.         letras[texto[i]].pop();
  23.  
  24.         ///Buscar cuántos mayores a P tengo en el set
  25.         int mayores = distance(s.begin(), s.upper_bound(p));
  26.         costoTotal += (p-i+(s.size()-1-mayores));
  27.  
  28.         s.insert(p);
  29.     }
  30.  
  31.     return costoTotal;
  32. }
  33.  
  34. int main()
  35. {
  36.     char l1[] = "Estamos pintando!";
  37.     char l2[] = "ostant!Em inpados";
  38.  
  39.     cout << procesador(l1, l2);
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment