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; }總結
以上是生活随笔為你收集整理的2019江西省赛F - String的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: LVDS,LVTTL,LVCOMS等常见
 - 下一篇: 5款神级软件,装机必备,不看后悔