Problem Description

Mickey is interested in probability recently. One day , he played a game which is about probability with mini.First mickey gives a letter and a word to mini.Then mini calculate the probability that the letter appears in the word.For example,give you the letter “a” and the word “apple”. the probability of this case is 0.20000.

Input

The input contains several test cases. Each test case consists of a letter and a word.The length of the word is no longer than 200.

Output

For each test case, print the probability rounded to five digits after the decimal point.

Sample Input

a apple

c Candy

a banana

Sample Output

0.20000

0.20000

0.50000

题意:

先输入一个字符,再输入一个字符串,然后输出该字符在字符串中占多少比例;保留5位小数。

属于简单题。

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String a = sc.next();
            String strs = sc.next();
            int anum = 0;
            String strss = "";
            for(int i=0;i<strs.length();i++){
                strss = strs.charAt(i)+"";
                if(a.equalsIgnoreCase(strss)){
                    anum++;
                }
            }
            double num = (double)((double)anum/(double)strs.length());
            System.out.printf("%.5f\t\n",num);
        }
    }
}

HDOJ 2131 Probability的更多相关文章

  1. HDU 2131 Probability

    http://acm.hdu.edu.cn/showproblem.php?pid=2131 Problem Description Mickey is interested in probabili ...

  2. (JAVA保留小数问题,基础)Probability hdu2131

    Probability 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2131 Time Limit: 3000/1000 MS (Java/Others) ...

  3. HDOJ 1009. Fat Mouse&#39; Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  5. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  6. 【BZOJ2318】Spoj4060 game with probability Problem 概率

    [BZOJ2318]Spoj4060 game with probability Problem Description Alice和Bob在玩一个游戏.有n个石子在这里,Alice和Bob轮流投掷硬 ...

  7. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  8. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

  9. HDOJ(2056)&amp;HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

随机推荐

  1. Linux工具快速教程

    看到一linux中常用工具使用教程,非常好.猛击下面的地址 github:https://github.com/me115/linuxtools_rst 在线文档:http://linuxtools- ...

  2. [求助] win7 x64 封装 出现 Administrator.xxxxx 的问题

    [求助] win7 x64 封装 出现 Administrator.xxxxx 的问题 jacky_qu 发表于 2014-9-3 23:34:37 https://www.itsk.com/thre ...

  3. securecrt中文乱码

    1.直接打开Linux的terminal中文字符显示正常,但是用securecrt登陆后中文显示不正常 解决方法:securecrt字符集设置不对 路径:Options -> Session O ...

  4. BAT面经

    http://bbs.csdn.net/topics/390734210?page=4 注意评论以及文章原地址

  5. JavaScript高级程序设计3.pdf

    do-while语句是一种后测试循环语句do {statement} while (expression),至少会循环一次 while语句是一种前测试循环语句while (expression) st ...

  6. class 添加样式,删除,开关 【选择】addClass,removeClass,toggleClass

    <1> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>< ...

  7. Binder机制,从Java到C (6. Binder in Native : libbinder)

    1.Java和C++中的Binder 从前一篇 Binder机制,从Java到C (5. IBinder对象传递形式) 中可以看到,使用Binder的Java代码,到最后都会进入到Native环境,将 ...

  8. libusb 开发者指南-牛胜超(转)

    源:libusb 开发者指南 libusb Developers Guidelibusb 开发者指南 原作者:Johannes Erdfelt翻译者:牛胜超 Table of Contents目录 P ...

  9. ES6 Generators并发

    ES6 Generators系列: ES6 Generators基本概念 深入研究ES6 Generators ES6 Generators的异步应用 ES6 Generators并发 如果你已经读过 ...

  10. 012_python在shell下单行执行多行代码

    一.有时候只是简单的获取下时间戳,不想在python解释器的交互模式下再去执行python代码,如何实现呢? 以循环输出多行为例: (1)第一种方式: python -c "exec(\&q ...