Avin has a string. He would like to uniform-randomly select four characters (selecting the same character is allowed) from it. You are asked to calculate the probability of the four characters being ”avin” in order.
Input
The first line contains n (1 ≤ n ≤ 100), the length of the string. The second line contains the string. To simplify the problem, the characters of the string are from ’a’, ’v’, ’i’, ’n’.
Output
Print the reduced fraction (the greatest common divisor of the numerator and denominator is 1), representing the probability. If the answer is 0, you should output “0/1”.
Sample Input
4
avin
4
aaaa
Sample Output
1/256
0/1
这道题真的超简单,结果在定义的时候着急了,马虎了,找了好久的错误才找到。
#include"stdio.h"
#include"math.h"
int gcd(int o,int p)
{
return p==0?o:gcd(p,o%p);
}
int main()
{
int n;
char a[150];
int x;
while(~scanf("%d",&n))
{
int sum=1;
int sum1=0;
int sum2=0;
int sum3=0;
int sum4=0;
scanf("%s",a);
for(int i=0;i<n;i++)
{
if(a[i]=='a')
{
sum1++;
}
if(a[i]=='v')
{
sum2++;
}
if(a[i]=='i')
{
sum3++;
}
if(a[i]=='n')
{
sum4++;
}
}
for(int i=0;i<4;i++)
{
sum=sum*n;
}
x=sum1*sum2*sum3*sum4;
if(x!=0)
{
if(gcd!=0)
{
printf("%d/%d\n",x/gcd(x,sum),sum/gcd(x,sum));
}
else
{
printf("%d/%d\n",x,sum);
}
}
else
{
printf("0/1\n");
}
}
return 0;
}