Problem Type : Number Theory
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define max 100
using namespace std;
unsigned long long fact(unsigned long long n)
{
unsigned long long i,ren=1;
for( i=1; i<=n; i++)
{
ren*=i;
}
return ren;
}
int main()
{
char ch[max];
unsigned long long int test,i,j,len,cou,k=0,store[max];
unsigned long long int sum,ans,sum1,m;
scanf("%llu",&test);
getchar();
while(test--)
{
k++;
scanf("%s",&ch);
len=strlen(ch);
sort(ch,ch+len);
// printf("%s\n",ch);
m=1;
for(i=0; i<len; i++)
{
cou=1;
for(j=i+1;j<len; j++)
{
if(ch[i]==ch[j])
{
cou++;
}
else
break;
}
if(cou!=1)
{
store[m]=cou;
m++;
i=j-1;
}
}
sum=1;
for(i=1; i<=len; i++)
{
sum*=i;
}
ans=1;
for(i=1; i<m; i++)
{
ans = ans * fact(store[i]);
}
sum1=sum/ans;
printf("Data set %llu: %llu\n",k,sum1);
memset(ch,'\0',sizeof(ch));
}
}
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define max 100
using namespace std;
unsigned long long fact(unsigned long long n)
{
unsigned long long i,ren=1;
for( i=1; i<=n; i++)
{
ren*=i;
}
return ren;
}
int main()
{
char ch[max];
unsigned long long int test,i,j,len,cou,k=0,store[max];
unsigned long long int sum,ans,sum1,m;
scanf("%llu",&test);
getchar();
while(test--)
{
k++;
scanf("%s",&ch);
len=strlen(ch);
sort(ch,ch+len);
// printf("%s\n",ch);
m=1;
for(i=0; i<len; i++)
{
cou=1;
for(j=i+1;j<len; j++)
{
if(ch[i]==ch[j])
{
cou++;
}
else
break;
}
if(cou!=1)
{
store[m]=cou;
m++;
i=j-1;
}
}
sum=1;
for(i=1; i<=len; i++)
{
sum*=i;
}
ans=1;
for(i=1; i<m; i++)
{
ans = ans * fact(store[i]);
}
sum1=sum/ans;
printf("Data set %llu: %llu\n",k,sum1);
memset(ch,'\0',sizeof(ch));
}
}
No comments:
Post a Comment