https://www.devskill.com/CodingProblems/ViewProblem/59
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll factorial(int n)
{
if(n == 0)
return 1;
return n * factorial(n - 1);
}
int main()
{
int t;
long long duplicate;
string s;
cin>>t;
while(t--){
cin>>s;
int total=0;
duplicate=1;
vector<int> alphabet(26, 0);
for(int j = 0; j < s.size(); j++){
alphabet[s[j] - 'a']++;
}
for(int j = 0; j < 26; j++){
if(alphabet[j]){
duplicate *= factorial(alphabet[j]);
total += alphabet[j];
}
}
cout<<factorial(total)/duplicate<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll factorial(int n)
{
if(n == 0)
return 1;
return n * factorial(n - 1);
}
int main()
{
int t;
long long duplicate;
string s;
cin>>t;
while(t--){
cin>>s;
int total=0;
duplicate=1;
vector<int> alphabet(26, 0);
for(int j = 0; j < s.size(); j++){
alphabet[s[j] - 'a']++;
}
for(int j = 0; j < 26; j++){
if(alphabet[j]){
duplicate *= factorial(alphabet[j]);
total += alphabet[j];
}
}
cout<<factorial(total)/duplicate<<endl;
}
return 0;
}
No comments:
Post a Comment