HDOJ 2131 Probability

来源:互联网 发布:最新软件毕业设计题目 编辑:程序博客网 时间:2024/06/18 00:05

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();        }    }}
原创粉丝点击