2019江西省赛F - String

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;
}
import xlrd def result_write(result,i,j):#result为txt文件,i为比赛项目,j为奖项等级 tmp_str='' tmp_num=0 if award_dict[i][j][0]!=0: result.write(j+'获奖人数为'+str(award_dict[i][j][0])+'人,姓名如下:\n') else: result.write(j+'获奖人数为0人\n') for j in award_dict[i][j][1:]: tmp_str+=j tmp_str+=' ' tmp_num+=1 if tmp_num==10:#每十人写入文件并换行 result.write(tmp_str+'\n') tmp_str='' tmp_num=0 if tmp_num!=0:#向文件写入不满十人的姓名组 result.write(tmp_str+'\n') result.write('\n') award_dict=dict() data= xlrd.open_workbook("C:\\Users\\游雏\\Downloads\\2022蓝桥江西省赛.xls") sheet1 = data.sheet_by_name("Sheet1") col = sheet1.col_values(4) award_class=[] for i in col[1:]:#获取比赛项目列表,首字母统一大写 if 'a'<=i[0]<='z': i=i[0].upper()+i[1:] if i not in award_class: award_class.append(i) for i in award_class:#创建一个嵌套字典,一级字典以比赛项目为键,二级字典以奖项等级为键,值为获奖人姓名列表 award_dict[i]=dict(一等奖=[0],二等奖=[0],三等奖=[0]) for i in range(sheet1.nrows):#按行遍历表格 if i==0:continue row = sheet1.row_values(i) if row[2]=='江西理工大学':#row[2]为学校名 if 'a'<=row[4][0]<='z':#row[4]为比赛项目 row[4]=row[4][0].upper()+row[4][1:] award_dict[row[4]][row[5]][0]+=1#统计某项目某奖项的获奖人数,row[5]为奖项等级 award_dict[row[4]][row[5]].append(row[3])#将获奖者姓名添入一级键为项目二级键为奖项的列表,row[3]为获奖者姓名 award_level=['一等奖','二等奖','三等奖'] result=open("resutl.txt", "w") for i in award_class: result.write(i+'\n') for j in award_level: result_write(result,i,j) result.write('\n') result.close()帮我优化此代码
最新发布
05-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值