原文地址:杭电2131 probability作者:追梦人 probability time limit: 30001000 ms (javaothers) memory limit:  k (javaothers) total s bmission(s): 2149 accepted s bmission(s): 1055 problem description mickey is interested in probability recently. one day , he played a game which is abo t probability with mini.first mickey gives a letter and a word to mini.then mini calc late the probability that the letter appears in the word.for example,give yo the letter "a" and the word "apple". the probability of this case is 0.. inp t the inp t contains several test cases. each test case consists of a letter and a word.the length of the word is no longer than 200. o tp t for each test case, print the probability ro nded to five digits after the decimal point. sample inp t a apple c candy a banana sample o tp t 0. 0. 0. 此题其实并不难,可是我还是犯了很弱智的错误,这也是不好好看课本的后果.还是先说一下思路吧: 要求是:先输入一个字母,然后再输入一个长度不超过200的字符串,计算该字母在字符串中所占的百分比,按题目要求是大小写按相同计算,但是c语言中大小写字母并不同,这就要求我们采取措施使他们相同.因此,可以使用tolower函数将大写字母转换为小写字母,此函数包含在ctype.h中.但是我还是wa了,因为x=(do ble)co ntlen;我定义的x为do ble型,co nt,len为int型,需进行强制类型转换或者在算是中*1.0,是结果为do ble型.惭愧! #incl destdio.h #incl dectype.h #incl destring.h int main { int co nt,len,i; do ble x; char l[2],s[201]; while(scanf("%s %s",l,s)!=eof) { if(l[0]= a &&l[0]= z ) l[0]=tolower(l[0]); co nt=0; len=strlen(s); for(i=0;ilen;i) { if(s[i]= a &&s[i]= z ) s[i]=tolower(s[i]); if(s[i]==l[0]) co nt; } x=(do ble)co ntlen;关键所在:强制转换类型 printf("%.5lfn",x);