Your code doesn't work!!!
I found mistake in my and got Accepted
Thanks anyway!!
Moderator: Board moderators
lord_burgos wrote:
- Code: Select all
Your welcom
Delete after AC


Input:
6
WEDDING
HAPPY
ADAM
ABABAAAAAAAAAAAAAAAA
A
MULTIPLICATION
Output:
Data set 1: 2520
Data set 2: 60
Data set 3: 12
Data set 4: 190
Data set 5: 1
Data set 6: 3632428800

-tells us to use atleast unsigned long.The number of arrangements will always be able to fit into an unsigned long int
- tells us to be careful and check for overflows.Note that 12! is the largest factorial that can fit into an unsigned long int
Note that 12! is the largest factorial that can fit into an unsigned long int
reduce and calculate, instead of calculating the numerator, the denominator & then division.


code deleted after acfor (i=0; i<len;i++) {
if (s[i]!=s[i-1]) {
...
...
cut after AC
#include<stdio.h>
#include<string.h>
int main()
{
char st[21],a[21];
int n,i,j,k,r,len,num[21],c=0;
bool found,enter;
scanf("%d",&n);getchar();
while(n--)
{
c++;
gets(st);
len = strlen(st);j=0;k=1;
for(i=0;st[i];i++)
{
if(i>0)
{
found=0;
for(j=0;j<k;j++)
{
if(a[j]==st[i])
{
found=1;
num[j]+=1;
break;
}
}
if(!found){a[k]=st[i];num[k]=1;k++;}
}
else {a[0]=st[i];num[0]=1;}
}
long long int sum=1,sumr=0,temp=1;
r=len-k;
enter=1;
for(i=0;i<k;i++)if(num[i]>1){for(j=1;j<=num[i];j++)temp*=j;sumr+=temp;}
for(i=1;i<=len;i++){sum*=i;if(sum%sumr==0&&enter==1){sum/=sumr;enter=0;}}
printf("Data set %d: %lld\n",c,sum);
}
return 0;
}Users browsing this forum: Bing [Bot] and 0 guests