当前位置: 代码迷 >> 综合 >> HDOJ 2131 Probability
  详细解决方案

HDOJ 2131 Probability

热度:41   发布时间:2023-10-21 19:56:05.0

HDACM2131

水题,注意精度和大小写即可

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);while (sc.hasNext()) {String str = sc.nextLine();str = str.toLowerCase();char c[] = str.toCharArray();int count = 0;for (int i = 2; i < c.length; i++) {if (c[0]==c[i]) {count++;}}System.out.printf("%.5f",(1.0*count/(c.length-2)));System.out.println();}}
}