Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- string s;
- long fac (long num)
- {
- long resp=1;
- for(int i=2; i<=num; i++)
- resp=resp*i;
- return resp;
- }
- long mlp(long a, long b)
- {
- if (a==b) ///hay un solo palindromo
- return 1;
- map<char,int> mapa;
- for(int i=(a-1); i<b; i++)
- mapa[ s[i] ]++;
- long pares = 0; ///cantidad de duplas o pares
- long relleno = 0;
- /*cout<<endl;
- for (auto i : mapa)
- cout<< i.first<<" "<< i.second <<endl;*/
- map<char, int>::iterator it;
- for (it=mapa.begin(); it!=mapa.end(); it++)
- {
- if( it->second > 0 )
- {
- long par = it->second/2;
- pares += par;
- it->second -= 2*par;
- }
- if ( it->second )
- relleno++;
- }
- /*cout<<"["<<pares<<"-"<<relleno<<"]"<<endl;
- for (auto i : mapa)
- cout<< i.first<<" "<< i.second <<endl;*/
- if(!pares)
- return 0;
- if(!relleno)
- return fac(pares);
- return relleno*fac(pares);
- }
- int main()
- {
- long n, a, b;
- cin>>s>>n;
- for(int i=0; i<n; i++)
- {
- cin>>a>>b;
- cout<<mlp(a, b)<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment