Created
July 27, 2016 15:59
-
-
Save ravikiran0606/52d7ce52d5cdba3296cd021e0188cfa2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
unsigned long long calc[32]; | |
void compute() | |
{ | |
int i; | |
calc[0]=1; | |
for(i=1;i<=30;i++){ | |
calc[i]=i*calc[i-1]; | |
} | |
} | |
void solve(string s,int n) | |
{ | |
vector<int>v; | |
int i,c[27]={0}; | |
for(i=0;i<n;i++){ | |
if(s[i]<=90)s[i]+=32; | |
c[s[i]-'a']++; | |
} | |
int ans,c1,c2,flag; | |
c1=c2=flag=ans=0; | |
for(i=0;i<27;i++){ | |
if(c[i]%2==0){ | |
ans+=(c[i]/2); | |
if((c[i]/2)>1) | |
v.push_back(c[i]/2); | |
} | |
else{ | |
c2++; | |
} | |
if(c2>1) | |
{ | |
cout<<"-1"<<endl; | |
return; | |
} | |
} | |
unsigned long long sol=calc[ans]; | |
for(i=0;i<v.size();i++) | |
sol/=calc[v[i]]; | |
cout<<sol<<endl; | |
} | |
int main() | |
{ | |
ios_base::sync_with_stdio(false); | |
cin.tie(0); | |
cout.tie(0); | |
long int t; | |
compute(); | |
long long ans; | |
cin>>t; | |
string s; | |
while(t--){ | |
cin>>s; | |
solve(s,s.length()); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment