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' 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)&HDOJ(1086)

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

随机推荐

  1. Qt知识点、疑难杂症的治疗

    Q: QVariant 保存指针数据   A1: 1,使用QVariant::fromValue((void*)target)保存数据 2,使用(ShortcutItem*)(v.value<v ...

  2. Java基础知识强化之IO流笔记19:FileOutputStream的三个write方法

    1. FileOutputStream的三个write方法:  void write(byte[] buffer)           Writes the entire contents of th ...

  3. SGU 199 - Beautiful People 最长上升子序列LIS

    要邀请n个人参加party,每个人有力量值strength Si和魅力值 beauty Bi,如果存在两人S i ≤ S j and B i ≥ B j 或者  S i ≥ S j and B i ≤ ...

  4. Python Socket单线程+阻塞模式

    Python之旅]第五篇(二):Python Socket单线程+阻塞模式 python Socket单线程 Socket阻塞模式 串行发送 摘要:  前面第五篇(一)中的一个Socket例子其实就是 ...

  5. ASP.NET-FineUI开发实践-14

    以前写过一个表格自动补全,改下,就出现了部分级联修改.测试版本4.1.1 共享下JS,ext-part2.js       后台再来个得到数据的方法就可以了.   1.方法还是删除+插入,主要在  i ...

  6. JSP学习--常用作用域

    page:当前页面,也就是只要跳到别的页面就失效了 request:一次会话,简单的理解就是一次请求范围内有效 session:浏览器进程,只要当前页面没有被关闭(没有被程序强制清除),不管怎么跳转都 ...

  7. 移动页面缩放方法之(三)rem布局

    <!DOCTYPE HTML> <html lang="zh-cn"> <head> <meta http-equiv="Con ...

  8. Android中Application全局方法(变量)的调用

    Application和Actovotu,Service一样是android框架的一个系统组件,当android程序启动时系统会创建一个 application对象,用来存储系统的一些信息.通常我们是 ...

  9. Web弹框类

    using System; using System.Text; namespace Core { /// <summary> /// MessageBox 的摘要说明. /// < ...

  10. 如何修改mtk android 默认拍照size

    [DESCRIPTION] 修改默认拍照size [SOLUTION] 修改默认的capture size,改变camera feature table的FID_CAP_SIZE default值不起 ...