HDU 2131 Probability

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

求字母在单词中出现的概率,无视大小写

View Code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char sp,word[210];
    int i,len,cnt; 
    while(~scanf("%c%s%*c",&sp,word))
    {
        len=strlen(word);
        cnt=0;
        for(i=0;i<len;i++)
            if(word[i]==sp||word[i]==sp+32||word[i]==sp-32)
                cnt++;
        printf("%.5lf\n",1.0*cnt/len);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/xiaohongmao/p/2439807.html