String hdu-6572

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

因为是要挑出来四个字符看能组成avin的概率,所以只需要x=pow(n,4)就可以了

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n;string ss;
	while(cin>>n>>ss)
	{
		long long aa=0,vv=0,ii=0,nn=0;long long z=0;long long x=0;
		x=pow(n,4);
		for(int i=0;i<n;i++)
		{
			if(ss[i]=='a') aa++;
			else if(ss[i]=='v') vv++;
			else if(ss[i]=='i') ii++;
			else if(ss[i]=='n') nn++;
		}
		if(aa==0||vv==0||ii==0||nn==0) z=0;	
		else z=aa*vv*ii*nn;
		long long zx=__gcd(z,x);
		if(zx)
		{
			z=z/zx;
			x=x/zx;
		}
		cout<<z<<"/"<<x<<endl;
	}
	
	return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值