http://acm.hdu.edu.cn/showproblem.php?pid=2131

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
 
代码:

#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
char s[maxn];
char c; int main() {
while(~scanf("%c%s", &c, s)) {
getchar();
int len = strlen(s);
int cnt = 0;
for(int i = 0; i< len; i ++) {
if(s[i] == c || s[i] == c - 32 || s[i] == c + 32)
cnt ++;
}
printf("%.5lf\n", 1.0 * cnt / len);
}
return 0;
}

  

HDU 2131 Probability的更多相关文章

  1. HDOJ 2131 Probability

    Problem Description Mickey is interested in probability recently. One day , he played a game which i ...

  2. hdu 3354 Probability One

    Probability One Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  3. HDU 4978 A simple probability problem

    A simple probability problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  4. HDU 6595 Everything Is Generated In Equal Probability (期望dp,线性推导)

    Everything Is Generated In Equal Probability \[ Time Limit: 1000 ms\quad Memory Limit: 131072 kB \] ...

  5. hdu多校第二场 1005 (hdu6595) Everything Is Generated In Equal Probability

    题意: 给定一个N,随机从[1,N]里产生一个n,然后随机产生一个n个数的全排列,求出n的逆序数对的数量,加到cnt里,然后随机地取出这个全排列中的一个非连续子序列(注意这个子序列可以是原序列),再求 ...

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

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

  7. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  8. hdu 2955 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...

  9. HDU 2955 Robberies 背包概率DP

    A - Robberies Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

随机推荐

  1. c# 分析SQL语句中的表操作

    最近写了很多方向的总结和demo.基本包含了工作中的很多方面,毕竟c#已经高度封装并且提供了很多类库.前面已经总结了博文.最近2天突然感觉前面的SQL分析阻组件的确麻烦,也注意看了下.为了方便大家学习 ...

  2. SmallMQ发布

    最近一直学习,主要处理java的分布式,MQ,RPC,通信,数据库,缓存等方向. 一般现在的MQ都是企业级的,庞大,功能齐全.最主要是代码量大,对于我们这些小程序员而言,太大,修改困难,修复更加困难, ...

  3. Ajax跨域(jsonp) 调用JAVA后台

    1. JSONP定义    JSONP是英文JSON with Padding的缩写,是一个非官方的协议.它允许在服务器端生成script tags返回至客户端,通过javascript callba ...

  4. Java分享笔记:创建多线程 & 线程同步机制

    [1] 创建多线程的两种方式 1.1 通过继承Thread类创建多线程 1.定义Thread类的子类,重写run()方法,在run()方法体中编写子线程要执行的功能. 2.创建子线程的实例对象,相当于 ...

  5. hdu_2588_GCD

    The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the ...

  6. WinForm webbrowser控件的使用

    webbrowser是一个比较实用的工具,主要用于在winform窗体中嵌入浏览器,达到winform与webform互操作的目的. 先上一个demo,看一下能实现什么效果. private void ...

  7. linux系统编程之框架

    linux系统编程之框架: 1. 进程 1.1 进程概念 1.1.1 PCB 1.1.2 环境变量 1.2 进程控制 1.3 进程间通信 1.3.1 管道 1.3.2 有名管道 1.3.3 共享内存 ...

  8. python_day4_shopping

    购物车例子,实现显示商品信息,输入商品编号并且可以减去自己的存入余额,当商品价格大于自己的余额的时候,直接退出:当不再选择商品的时候,退出显示余额和已经添加的商品. #购物车程序 product_li ...

  9. jmeter 插件安装

    1.下载Plugins Manager插件 打开下载插件地址:https://jmeter-plugins.org/ 2.将下载的plugins-manager.jar包复制到Jmeter安装目录,l ...

  10. Python3爬虫(十二) 爬虫性能

    Infi-chu: http://www.cnblogs.com/Infi-chu/ 一.简单的循环串行一个一个循环,耗时是最长的,是所有的时间综合 import requests url_list ...