Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
26818 唐心 字母概率 C++ Accepted 7 MS 764 KB 524 2022-05-24 17:03:45

Tests(1/1):


Code:

#include <iostream> #include <cstdlib> #include <cstring> using namespace std; int main() { int i,n=0,num,j; char str[200]; char c; while((c = getchar())!=EOF) { if(c>='A'&&c<='Z') c = c+32; n = 0; memset(str,0,sizeof(str)); cin >>str; num = strlen(str); for(j=0;j<num;j++) { if(str[j]>='A'&&str[j]<='Z') str[j] = str[j]+32; } for(j=0;j<num;j++) { if(str[j] == c) n++; } printf("%.5lf\n",n*1.0/num); getchar();//读取换行 } return 0; }