AlenAntonelli

defectu0s0, divici0n m0duIar

Jun 3rd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. using namespace std;
  5.  
  6. string s;
  7.  
  8. long fac (long num)
  9. {
  10. long resp=1;
  11. for(int i=2; i<=num; i++)
  12. resp=resp*i;
  13.  
  14. return resp;
  15. }
  16.  
  17. long mlp(long a, long b)
  18. {
  19. if (a==b) ///hay un solo palindromo
  20. return 1;
  21.  
  22.  
  23.  
  24. map<char,int> mapa;
  25. for(int i=(a-1); i<b; i++)
  26. mapa[ s[i] ]++;
  27.  
  28.  
  29. long pares = 0; ///cantidad de duplas o pares
  30. long relleno = 0;
  31.  
  32. /*cout<<endl;
  33. for (auto i : mapa)
  34. cout<< i.first<<" "<< i.second <<endl;*/
  35.  
  36. map<char, int>::iterator it;
  37. for (it=mapa.begin(); it!=mapa.end(); it++)
  38. {
  39. if( it->second > 0 )
  40. {
  41. long par = it->second/2;
  42. pares += par;
  43. it->second -= 2*par;
  44. }
  45. if ( it->second )
  46. relleno++;
  47. }
  48.  
  49. /*cout<<"["<<pares<<"-"<<relleno<<"]"<<endl;
  50. for (auto i : mapa)
  51. cout<< i.first<<" "<< i.second <<endl;*/
  52.  
  53. if(!pares)
  54. return 0;
  55. if(!relleno)
  56. return fac(pares);
  57. return relleno*fac(pares);
  58. }
  59.  
  60. int main()
  61. {
  62. long n, a, b;
  63. cin>>s>>n;
  64.  
  65. for(int i=0; i<n; i++)
  66. {
  67. cin>>a>>b;
  68. cout<<mlp(a, b)<<endl;
  69. }
  70.  
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment