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. cocos2d-x项目过程记录(跨平台iOS和Android)

    (原创作品,欢迎转载,注明出处,谢谢:http://www.cnblogs.com/binxindoudou/admin/EditPosts.aspx?postid=3205249) 1.配置环境,重 ...

  2. Java基础知识强化之IO流笔记08:异常的注意事项

    1. 异常注意事项: (1)子类重写父类方法时候,子类的方法必须抛出相同的异常或者父类异常的子类.(父亲坏了,儿子不能比父亲更坏) (2)如果父类抛出多个异常,子类重写父类时候,只能抛出相同的异常或者 ...

  3. Codeforces 526D - Om Nom and Necklace 【KMP】

    ZeptoLab Code Rush 2015 D. Om Nom and Necklace [题意] 给出一个字符串s,判断其各个前缀是否是 ABABA…ABA的形式(A和B都可以为空,且A有Q+1 ...

  4. HDU5327

    #include <iostream> #include <stdio.h> #include <cstring> using namespace std; int ...

  5. Android之使用json进行网络数据交换

    JSON作为一种轻量级的数据交换格式,凭借其易于阅读和编写.易于解析.传输速度快等优点流行了起来.最近正好在学习Android端从服务端端取数据,Json便派上了用场.好,下面开始切入主题. 1.准备 ...

  6. mssql sql高效关联子查询的update 批量更新

    /* 使用带关联子查询的Update更新     --1.创建测试表 create TABLE Table1     (     a varchar(10),     b varchar(10),   ...

  7. scn转换为十进制

  8. AFNetworking使用详解

    导语: 众所周知,AFNetworking是目前IOS开发中非常受欢迎的第三方网络通信类库,同时AFNetworking对苹果官方NSURLConnection和NSURLSession进行了封装,使 ...

  9. 苹果被拒的血泪史。。。(update 2015.11)

    项目提交了N此了,也审核N次了,苹果的审核机制依旧那么不急不慢.昨天刚刚又被拒了.回忆下之前的,总结一下吧. 2015.04.28 昨天被拒非常亏,app的评级是17+,但是在app展示图里有一个比较 ...

  10. 虚拟器运行iOS8地图提示错误

    /SourceCache/ProtocolBuffer_Sim/ProtocolBuffer-225/Runtime/PBRequester.m:799 server (https://gsp13-c ...